lua:delayfunction
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| lua:delayfunction [2014/12/27 07:17] – vodur | lua:delayfunction [2026/10/13 21:21] (current) – removed - external edit (Unknown date) 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | Syntax: delay( seconds[number], | ||
| - | |||
| - | Begins a countdown to execute the provided function after the specified number of seconds. The provided function will run in the env of the actor, no matter what env the delay is invoked from. If the actor is destroyed by the time the function should run, it will simply not run. | ||
| - | |||
| - | Example1: | ||
| - | |||
| - | function do_stuff() | ||
| - | |||
| - | goto(31404) | ||
| - | |||
| - | mdo(" | ||
| - | |||
| - | goto(10204) | ||
| - | |||
| - | end | ||
| - | |||
| - | delay(10, do_stuff) | ||
| - | |||
| - | Example2: | ||
| - | |||
| - | delay(10, function() | ||
| - | |||
| - | < | ||
| - | goto(31404) | ||
| - | </ | ||
| - | |||
| - | < | ||
| - | mdo(" | ||
| - | </ | ||
| - | |||
| - | < | ||
| - | goto(10204) | ||
| - | </ | ||
| - | |||
| - | < | ||
| - | end) | ||
| - | </ | ||
| - | |||
| - | Example3: | ||
| - | |||
| - | delay(10, function() | ||
| - | |||
| - | < | ||
| - | goto(31404) | ||
| - | </ | ||
| - | |||
| - | < | ||
| - | mdo(" | ||
| - | </ | ||
| - | |||
| - | < | ||
| - | goto(10204) | ||
| - | </ | ||
| - | |||
| - | < | ||
| - | end, | ||
| - | </ | ||
| - | |||
| - | < | ||
| - | " | ||
| - | </ | ||
| - | |||
| - | Notes: Remember that the delayed function will run in the env of the actor. Consider this example: | ||
| - | |||
| - | – let's say it's an mprog, ' | ||
| - | |||
| - | mob: | ||
| - | |||
| - | < | ||
| - | ch: | ||
| - | </ | ||
| - | |||
| - | < | ||
| - | ch: | ||
| - | </ | ||
| - | |||
| - | < | ||
| - | ch: | ||
| - | </ | ||
| - | |||
| - | < | ||
| - | end) | ||
| - | </ | ||
| - | |||
| - | This will work fine, but would not run if ' | ||
| - | |||
| - | However: | ||
| - | |||
| - | ch: | ||
| - | |||
| - | < | ||
| - | mob: | ||
| - | </ | ||
| - | |||
| - | < | ||
| - | mob: | ||
| - | </ | ||
| - | |||
| - | < | ||
| - | mob: | ||
| - | </ | ||
| - | |||
| - | < | ||
| - | end) | ||
| - | </ | ||
| - | |||
| - | This one may not do what you expect. Since this will run in the env of ' | ||
| - | |||
| - | [[http:// | ||
| - | |||
| - | So when you pass the function to delay, if any of the references in the function match ' | ||
| - | |||
| - | If global variables need to be passed to the delayed function, they must first be declared locally as below: | ||
| - | |||
| - | local lmob=mob – the original ' | ||
| - | |||
| - | ch: | ||
| - | |||
| - | < | ||
| - | lmob: | ||
| - | </ | ||
| - | |||
| - | < | ||
| - | lmob: | ||
| - | </ | ||
| - | |||
| - | < | ||
| - | lmob: | ||
| - | </ | ||
| - | |||
| - | < | ||
| - | end) | ||
| - | </ | ||
| - | |||
| - | Exploding mob: | ||
| - | |||
| - | – EXPLODING MOB!!!! | ||
| - | |||
| - | – ' | ||
| - | |||
| - | explode=explode or function() | ||
| - | |||
| - | < | ||
| - | echo(" | ||
| - | </ | ||
| - | |||
| - | < | ||
| - | for k,v in pairs(mob.room.players) do | ||
| - | </ | ||
| - | |||
| - | < | ||
| - | damage("' | ||
| - | </ | ||
| - | |||
| - | < | ||
| - | end | ||
| - | </ | ||
| - | |||
| - | < | ||
| - | mob: | ||
| - | </ | ||
| - | |||
| - | end | ||
| - | |||
| - | – only start exploding once, it's all we need! | ||
| - | |||
| - | if timerStarted==true then return end | ||
| - | |||
| - | delay(60, explode) – If mob isn't dead within 60 secs it will explode! | ||
| - | |||
| - | timerStarted=true | ||
| - | |||
| - | Since areas are never destroyed, AREA: | ||
| - | |||
| - | The actual delay time may be up to 1 second longer than the value provided. So delay(0, func) will run func 0-1 seconds after executed. | ||
| - | |||
| - | See also cancel | ||
lua/delayfunction.1419664657.txt.gz · Last modified: by vodur
