My function sendQueue() is meant to provide a means to very quickly set up a variety of different queues. Its basic syntax is:
sendQueue({"first action", first condition, "second action", second condition, "third action", third condition, "fourth action"})
(Of course you can make this as long as you want; it doesn't have to stop after four actions.)
"first action" etc.: These are primarily things you wish to send to the mud, such as "eat bread" or "climb tree" or "north". You may, however, also put aliases in there. If you have an alias to kick a rat on the pattern ^kill$ you can also use "kill" as an action in the queue.
first condition etc.: These are the conditions that must be fulfilled before the next action is executed. Conditions can be one of three things:
1. A number: If you use a number for a condition, it is interpreted as a delay time between the action before it and the action after it. If you use the number 0 here, the next action will be executed immediately.
2. A string: If you use a string for a condition (e.g. "onBalance"), it is interpreted as an event that must be raised for the next action to execute.
3. A table: If you use a table consisting of exactly one string element for a condition (e.g. {"^You see a bird flying above your head\.$"}) it is interpreted as a regex trigger that must match for the next action to be called.
You can mix all those up however you wish. For example:
sendQueue({"north", 0, "northeast", 0, "climb tree", "onBalance", "jump down", {"You land on the floor."}, "dig hole", 5, "climb in hole"})
This means: Go north, then immediately northeast, then immediately climb a tree. Wait until you recover balance, then jump down. As soon as you see yourself landing on the floor, dig a hole, wait 5 seconds then climb into the hole.
Note: It is important that you -always- keep to the order action-condition-action-condition. The first and last item in the table must always be an action, and there must -always- be a condition between two actions.
I use this for a wide variety of different things. For example I have a group of speedwalking paths stored like this:
paths = {
tasurke = {"remove shackle", 0, "say duanatharan", 0, "/ne,w,3gne4n", "onSpeedwalkComplete", "wear shackle"},
northern_wilderness = {"remove shackle", 0, "say duanatharan", 0, "/nw,2s", "onSpeedwalkComplete", "worm warp", "onEquilibrium", "/2e", "onSpeedwalkComplete", "worm warp", "onEquilibrium", "enter wilderness", "onWilderness", "wear shackle"},
kawhe = {"remove shackle", 0, "say duanathar", 0, "/w,ne,n,ne", "onSpeedwalkComplete", "worm warp", "onEquilibrium", "/2s,w", 0, "wear shackle"}
}
then I can simply execute sendQueue(paths.tasurke) and it will execute the commands to get me there.
Or, I could use this to put up my defences:
sendQueue({"dc",0,"vc",0, "nightsight",0,"thirdeye", "onBalance", "selfishness",
"onEquilibrium", "lifevision", 0, "nightsight", "onEquilibrium", "deathsight",
"onEquilibrium", "scales"})
Here's the code:
As you may notice upon studying the code, it provides also a few other ways of interacting with your queues.
First of all, every queue gets assigned an individual ID upon creation which it returns. Using this ID, you can influence how the queue is executed, using the following terms:
sendQueue(ID, "next") -> This executes the next action in the queue immediately, without waiting for the condition to be fulfilled.
sendQueue(ID, "abort") -> This aborts the whole queue and deletes it.
sendQueue(ID, "pause") -> This pauses the whole queue, meaning that even if the next condition is fulfilled it won't execute anything until you do:
sendQueue(ID, "continue") -> This continues the execution of a queue after pausing it.
P.S. In order to make this work with events as well, you will have to add all events you want to use with this as "User Defined Event Handlers" on top of the script.