Stopping an Alias

Posted by Seahawk on Mon 12 Jul 2010 09:52 PM — 4 posts, 14,846 views.

#0
So, for multiple MUD's, I use the wait.time delay in Lua to create long aliases for performance.

---
Eg (one I plan to use to run an event)-

require "wait"
wait.make (function ()

Send ("event Capture the Flag is about to start! Listen up for the rules!")
wait.time ("5")
Send ("event One random person will be named the flag bearer to begin with. At all times, the flag bearer is allowed to attack anyone, but everyone else can only attack the flag bearer and not each other!")
wait.time ("15")
Send ("event To join the event, just type ARENA!")
wait.time ("5")
Send ("arena 100 desert 1")
wait.time ("3")
Send ("Everyone, I will now choose the flag bearer!")

end)

-----

So that takes approximately 30 seconds. Now, if something came up in those 30 seconds, I might want to stop the rest of the alias from proceeding.

Is there any way to do this without resorting to breaking all those parts into individual aliases and doing them all manually?
USA #1
require "wait"
wait.make (function ()
SetVariable("stop_alias_foo", "0")

Send ("event Capture the Flag is about to start! Listen up for the rules!")
wait.time ("5")
if GetVariable("stop_alias_foo") == "1"
  return
end
Send ("event One random person will be named the flag bearer to begin with. At all times, the flag bearer is allowed to attack anyone, but everyone else can only attack the flag bearer and not each other!")
wait.time ("15")
if GetVariable("stop_alias_foo") == "1"
  return
end
Send ("event To join the event, just type ARENA!")
wait.time ("5")
if GetVariable("stop_alias_foo") == "1"
  return
end
Send ("arena 100 desert 1")
wait.time ("3")
if GetVariable("stop_alias_foo") == "1"
  return
end
Send ("Everyone, I will now choose the flag bearer!")

end)


Probably the simplest/quickest approach. Write another alias that sets the stop_alias_foo variable to "1", and when this alias resumes, it'll see it and stop.
Australia Forum Administrator #2
Yes indeed. And in the spirit of not repeating code, encapsulate all that:



require "wait"
wait.make (function ()

  local function mywait (n)
    wait.time (n)
    return GetVariable("stop_alias_foo") == "1"
  end -- mywait
  
  -- clear the flag which stops the alias
  SetVariable("stop_alias_foo", "0") 

  Send ("event Capture the Flag is about to start!...")
  if mywait (5) then return end
  Send ("event One random person will be named the flag bearer to begin with. ...")
  if mywait (15) then return end
  Send ("event To join the event, just type ARENA!")
  if mywait (5) then return end
  Send ("arena 100 desert 1")
  if mywait (3) then return end
  Send ("Everyone, I will now choose the flag bearer!")

end)


The function mywait does the pause, and tests the flag (which as Twisol said, you set up in another alias). If it matches, it returns true, which you use to break out of the main alias.
Amended on Mon 12 Jul 2010 10:24 PM by Nick Gammon
Australia Forum Administrator #3
In fact in this case you could build the Send into mywait too, to make the main thing even shorter (just send down whatever it is you want to display).