Nick Gammon said:
Generally when you seem to have hit a limitation of the language you need to revisit what you are doing. For example, if you are processing afflictions, and you want to queue up a cure, do a simple keyed lookup (or sequential lookup) of your queue of things you are planning to cure, to see if it is there already. But not by trying to compare functions per se. Stick to affliction names or cure names, or something more high level.
This is what I am doing:
-I have a vector with all the afflictions, in the order I want to cure them, from the most dangerous to the least dangerous.
-I have a module affs which adds the affliction when I get the affliction message: affs:add (affliction) (the new affliction is stored in the the affs ["current"] table).
The line for an affliction can be an illusion (another player used a skill to make you see the line). And if it is an illusion, there is a possibility that you detect the illusion before the prompt. You detect it based on a % chance (there is a skill), or by checking against different things (like if the illusion was supposed to prone you, you can check for prone at the next prompt-the prompt shows without a doubt when you are prone-, and a few other means).
Sometimes you can be certain that an affliction line is not an illusion (for that I use affs:add), and other times you cannot (I use the queue for that).
I am not using the queue only for afflictions and I sometimes need the queue to execute a set of functions that are only used with that trigger, like this (just an example):
prompt:queue (function () EnableTrigger ("name") affs:add ("affliction") Note ("AFFLICTION")end)
And I need to be sure I am not queued the same function twice.
When I detect an illusion, I delete certain queued function (for that I use another table entry in the prompt queue), which I previously marked for deletion when I stored them into the queue (this is the previous function, marked for deletion):
prompt:queue (function () EnableTrigger ("name") affs:add ("affliction") Note ("AFFLICTION")end, "delete_it_if_illusion")
That is a little besides the point, the problem still remains, I need an unique name for the function for both comparing with previous entries in the queue, and for storing it for removal in case of an illusion. Problem which I solved by assigning an unique id for the function queued, like this ("affs_add_paralysis" is the id):
prompt:queue (function () affs:add ("paralysis") end, "affs_add_paralysis", "delete_it_if_illusion")
|