Executing timed aliases gathering trigger data

Posted by ErockMahan on Mon 04 Oct 2010 10:36 PM — 4 posts, 19,524 views.

#0
Bob gives me an item, which sets a variable and then executes an alias 3 seconds later (with 'doafterspecial'), but for some reason the alias does not pick up the variable change.

Is 3 seconds not long enough to register the change, or is there something fundamental about the way Mushclient works that won't allow all these things to happen without a manually executed command?
USA #1
Without seeing the alias, I can only make a guess. I think my guess is a good one, but if I'm wrong, please copy your alias and paste it here in your next post.

Template:copying
For advice on how to copy aliases, timers or triggers from within MUSHclient, and paste them into a forum message, please see Copying XML.


At any rate, I'm guessing you have something like this:
DoAfter(3, "foo @myvar")

This is a little technical, but the problem is that the "@variable_name" syntax is not actually part of a scripting language. It's something MUSHclient provides on top, just like the wildcard %1 syntax. It does this by processing the script first itself, replacing %1 inline with the wildcard and @myvar inline with the variable's contents. So even before the script is actually executed, the above becomes:
DoAfter(3, "foo value")

As you can see, the variable was evaluated before the delayed command executes 3 seconds later. The solution is simple:
DoAfterSpecial(3, [[Send("foo " .. GetVariable("myvar"))]], send_to.script)

Note that I'm using the script function GetVariable, instead of relying on the @myvar shorthand. This ensures that it's the script itself that accesses the variable when it's supposed to, not the MUSHclient preprocessor. Also note that I'm using Lua long-style strings (the [[contents]] thing). This is just so I can use double-quotes in the delayed script; if you're using another language you'll probably do something like use "" for the delayed script and '' for the quotes inside it.

TL;DR: Use this:
DoAfterSpecial(3, [[Send("foo " .. GetVariable("myvar"))]], send_to.script)
Amended on Mon 04 Oct 2010 11:25 PM by Twisol
Australia Forum Administrator #2
ErockMahan said:

Bob gives me an item, which sets a variable and then executes an alias 3 seconds later (with 'doafterspecial'), but for some reason the alias does not pick up the variable change.


I agree with what Twisol said, but the other thing is "what variable change"? His solution will pick up the variable at the time the delayed alias is called (which may or may not be what you want exactly - maybe the variable changes again 2 seconds later).

Also, if the thing you are doing is an alias (which you said it was) then Send is wrong, it should be Execute, like this:


DoAfterSpecial(3, 'Execute ("foo " .. GetVariable ("myvar"))', sendto.script)


(Note: sendto.script, not send_to.script).

That way "foo" is treated as an alias, and not just sent to the MUD.

However if I read your post correctly, you want to set a variable, and then use that new variable 3 seconds later. In which case this should work:


DoAfter (3, "foo " .. GetVariable ("myvar"))


This will concatenate your alias with the new contents of the variable, and then do that 3 seconds later.

However if you had (as Twisol guessed):


DoAfter (3, "foo @myvar")


Then you get the old value of the variable, not the one you just set.
Amended on Mon 11 Oct 2010 10:57 PM by Nick Gammon
#3
I think Nick nailed it - the problem is that I'm getting variable information with @, which doesn't pick up the changes since the original execution. I'll try "getting" the variables and see if that doesn't make the difference.