Variables in Timers

Posted by Lilbopeep on Wed 09 Sep 2009 05:22 AM — 3 posts, 15,007 views.

USA #0
Simply put, is it possible? I don't see an 'expand variables' option.

making scrolls on my mud is a tedious, often scripted process, but they are fairly handy to have. My solution was to make an alias that would turn on and off a 3 minute timer, which just about perfect for how long it takes to create the parchment object and write the spell onto it.

This all worked fine and dandy, but it only made scrolls of whatever spell I specified, so I thought.. improve it!

Now, I have an alias:


<aliases>
  <alias
   match="scrollmaker *"
   enabled="y"
   expand_variables="y"
   send_to="12"
   sequence="100"
  >
  <send>
if "%1" == "off" then
EnableTimer ("scroll_timer", false)
Note ("Turning off the Scroll Timer.")
else
SetVariable("spell", "%1")
EnableTimer ("scroll_timer", true)
Note ("Turning on the Scroll Timer with spell @spell")
end
</send>
  </alias>
</aliases>


the off part works fine. But the weird thing is, it seems to be giving the previous variable. If I typed 'scrollmaker blackmantle' it would give me what I typed in before?

Example:


>scrollmaker blackmantle
Turning on the Scroll Timer with spell blackmantle
>scrollmaker shriek
Turning on the Scroll Timer with spell blackmantle
>scrollmaker slow
Turning on the Scroll Timer with spell shriek


This also doesn't even address the problem that my timer isn't doing either of these.

the line that is failing in my alias is:

scribe '@spell'

Also, I am not sure if two word spells are already handled properly - it seems to work in the variable, but I've not been able to get beyond that to make sure.

Any ideas?
Amended on Fri 11 Sep 2009 11:08 PM by Nick Gammon
Australia Forum Administrator #1
Timers don't have an "expand variables" option, but you can do it in scripting, same as in aliases.

Quote:

SetVariable("spell", "%1")
EnableTimer ("scroll_timer", true)
Note ("Turning on the Scroll Timer with spell @spell")


Your problem here is that, when executing a script, MUSHclient replaces @spell by the value in the spell variable *before* executing the code. Thus, changing the variable mid-stream won't affect it. However all you need to do is this:


SetVariable("spell", "%1")
EnableTimer ("scroll_timer", true)
Note ("Turning on the Scroll Timer with spell " .. GetVariable ("spell") )


In this case the GetVariable is executed at runtime, so it will get the right variable. Or, more simply:


SetVariable("spell", "%1")
EnableTimer ("scroll_timer", true)
Note ("Turning on the Scroll Timer with spell %1")



Inside your scroll timer, you can use GetVariable as well. So for example if you wanted to cast "spell" every 5 seconds you could do this:


Send ("cast " .. GetVariable "spell")


USA #2
thanks nick! It's working wonderfully!