Difference between revisions of "User:Dt192/Sandbox2"
Jump to navigation
Jump to search
(Blanked the page) Tag: Blanking |
m |
||
| Line 1: | Line 1: | ||
| + | <syntaxhighlight lang="lua"> | ||
| + | enableTimer("Newbie timer") -- enables the timer, so 2s after being enabled, it'll tick - and every 2s after that | ||
| + | disableTimer("Newbie timer") -- disables it, so it won't go off anymore | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | |||
| + | |||
| + | <syntaxhighlight lang="lua"> | ||
| + | tempTimer(3, [[ echo("this is timer #1 going off 3s after being made\n") ]]) | ||
| + | tempTimer(4, [[ echo("this is timer #2 going off 4s after being made - and 1s after the first one\n") ]]) | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | |||
| + | |||
| + | <syntaxhighlight lang="lua"> | ||
| + | -- get and store the timer ID in the global "greeting_timer_id" variable | ||
| + | greeting_timer_id = tempTimer(2, [[ echo("hello!\n") ]]) | ||
| + | |||
| + | -- delete the timer - thus nothing will actually happen! | ||
| + | killTimer(greeting_timer_id) | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | |||
| + | |||
| + | <syntaxhighlight lang="lua"> | ||
| + | if portal_timer then killTimer(portal_timer) end | ||
| + | portal_timer = tempTimer(2, [[ send("enter portal") ]]) | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | |||
| + | |||
| + | <syntaxhighlight lang="lua"> | ||
| + | tid = tempTimer(600, [[echo("\nYour ten minutes are up.\n")]]) | ||
| + | echo("\nYou have " .. remainingTime(tid) .. " seconds left, use it wisely... \n") | ||
| + | |||
| + | -- Will produce something like: | ||
| + | |||
| + | --> You have 599.923 seconds left, use it wisely... | ||
| + | |||
| + | -- Then ten minutes time later: | ||
| + | |||
| + | --> Your ten minutes are up. | ||
| + | |||
| + | </syntaxhighlight> | ||
| + | |||
| + | |||
| + | |||
| + | <syntaxhighlight lang="lua"> | ||
| + | tempTimer(1.4, [[ echo("hello, "..matches[2].."!\n") ]]) | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | |||
| + | |||
| + | <syntaxhighlight lang="lua"> | ||
| + | tempTimer(1.4, [[ echo("hello, ]]..matches[2]..[[!\n") ]]) | ||
| + | |||
| + | -- or with less brackets: | ||
| + | tempTimer(1.4, function() echo("hello, "..matches[2].."!\n") end) | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | |||
| + | |||
| + | <syntaxhighlight lang="lua"> | ||
| + | tempTimer(1, [=[ | ||
| + | echo("this is timer #1 reporting, 1s after being made!\n") | ||
| + | tempTimer(1, [[ | ||
| + | echo("this is timer #2 reporting, 1s after the first one and 2s after the start\n") | ||
| + | ]]) | ||
| + | ]=]) | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | |||
| + | |||
| + | <syntaxhighlight lang="lua"> | ||
| + | tempTimer(1, [==[ | ||
| + | echo("this is timer #1 reporting, 1s after being made!\n") | ||
| + | tempTimer(1, [=[ | ||
| + | echo("this is timer #2 reporting, 1s after the first one and 2s after the start\n") | ||
| + | |||
| + | tempTimer(1, [[ | ||
| + | echo("this is timer #2 reporting, 1s after the second one, 2s after the first one, 3s after the start\n") | ||
| + | ]]) | ||
| + | ]=]) | ||
| + | ]==]) | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | |||
| + | |||
| + | <syntaxhighlight lang="lua"> | ||
| + | local name = matches[2] | ||
| + | tempTimer(2.4, function() echo("hello, "..name.."!\n") end) | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | |||
| + | |||
| + | <syntaxhighlight lang="lua"> | ||
| + | enableTrigger("Get enemy list") | ||
| + | tempTimer(3, [[disableTrigger("Get enemy list")]]) | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | |||
| + | |||
| + | <syntaxhighlight lang="lua"> | ||
| + | -- in a script, this will run after all scripts were loaded - including the system, wherever in the order it is. | ||
| + | tempTimer(0, function() | ||
| + | print("this timer is running after all triggers have run") | ||
| + | end) | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | |||
| + | |||
| + | <syntaxhighlight lang="lua"> | ||
| + | fightStopWatch = fightStopWatch or createStopWatch() -- create, or re-use a stopwatch, and store the watch variable ID in a global variable to access it from anywhere | ||
| + | |||
| + | -- then you start the stopwatch in some trigger/alias/script with; | ||
| + | startStopWatch(fightStopWatch) | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | |||
| + | |||
| + | <syntaxhighlight lang="lua"> | ||
| + | fightStopWatch = fightStopWatch or createStopWatch(true) | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | |||
| + | |||
| + | <syntaxhighlight lang="lua"> | ||
| + | -- in a trigger script for example you can write: | ||
| + | fightTime = stopStopWatch(fightStopWatch) | ||
| + | echo("The fight lasted for " .. fightTime .. " seconds.") | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | |||
| + | |||
| + | <syntaxhighlight lang="lua"> | ||
| + | resetStopWatch(fightStopWatch) | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | |||
| + | |||
| + | <syntaxhighlight lang="lua"> | ||
| + | deleteStopWatch(fightTime) | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | |||
| + | |||
| + | <syntaxhighlight lang="lua"> | ||
| + | fightStopWatch = fightStopWatch or createStopWatch("Fight Stopwatch", true) -- using the name 'Fight Stopwatch' and starting it automatically | ||
| + | |||
| + | -- some time has passed | ||
| + | |||
| + | stopStopWatch("Fight Stopwatch") | ||
| + | echo("The fight lasted for " .. getStopWatchTime("Fight Stopwatch") .. " seconds.") | ||
| + | resetStopWatch("Fight Stopwatch") | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | |||
| + | |||
| + | <syntaxhighlight lang="lua"> | ||
| + | fightStopWatch = fightStopWatch or createStopWatch("Fight Stopwatch") | ||
| + | setStopWatchPersistence("Fight Stopwatch") -- enable this stopwatch to persist over Mudlet sessions | ||
| + | display(getStopWatches()) -- will now show that the stopwatch is persistent | ||
| + | </syntaxhighlight> | ||
Revision as of 00:26, 16 February 2026
enableTimer("Newbie timer") -- enables the timer, so 2s after being enabled, it'll tick - and every 2s after that
disableTimer("Newbie timer") -- disables it, so it won't go off anymore
tempTimer(3, [[ echo("this is timer #1 going off 3s after being made\n") ]])
tempTimer(4, [[ echo("this is timer #2 going off 4s after being made - and 1s after the first one\n") ]])
-- get and store the timer ID in the global "greeting_timer_id" variable
greeting_timer_id = tempTimer(2, [[ echo("hello!\n") ]])
-- delete the timer - thus nothing will actually happen!
killTimer(greeting_timer_id)
if portal_timer then killTimer(portal_timer) end
portal_timer = tempTimer(2, [[ send("enter portal") ]])
tid = tempTimer(600, [[echo("\nYour ten minutes are up.\n")]])
echo("\nYou have " .. remainingTime(tid) .. " seconds left, use it wisely... \n")
-- Will produce something like:
--> You have 599.923 seconds left, use it wisely...
-- Then ten minutes time later:
--> Your ten minutes are up.
tempTimer(1.4, [[ echo("hello, "..matches[2].."!\n") ]])
tempTimer(1.4, [[ echo("hello, ]]..matches[2]..[[!\n") ]])
-- or with less brackets:
tempTimer(1.4, function() echo("hello, "..matches[2].."!\n") end)
tempTimer(1, [=[
echo("this is timer #1 reporting, 1s after being made!\n")
tempTimer(1, [[
echo("this is timer #2 reporting, 1s after the first one and 2s after the start\n")
]])
]=])
tempTimer(1, [==[
echo("this is timer #1 reporting, 1s after being made!\n")
tempTimer(1, [=[
echo("this is timer #2 reporting, 1s after the first one and 2s after the start\n")
tempTimer(1, [[
echo("this is timer #2 reporting, 1s after the second one, 2s after the first one, 3s after the start\n")
]])
]=])
]==])
local name = matches[2]
tempTimer(2.4, function() echo("hello, "..name.."!\n") end)
enableTrigger("Get enemy list")
tempTimer(3, [[disableTrigger("Get enemy list")]])
-- in a script, this will run after all scripts were loaded - including the system, wherever in the order it is.
tempTimer(0, function()
print("this timer is running after all triggers have run")
end)
fightStopWatch = fightStopWatch or createStopWatch() -- create, or re-use a stopwatch, and store the watch variable ID in a global variable to access it from anywhere
-- then you start the stopwatch in some trigger/alias/script with;
startStopWatch(fightStopWatch)
fightStopWatch = fightStopWatch or createStopWatch(true)
-- in a trigger script for example you can write:
fightTime = stopStopWatch(fightStopWatch)
echo("The fight lasted for " .. fightTime .. " seconds.")
resetStopWatch(fightStopWatch)
deleteStopWatch(fightTime)
fightStopWatch = fightStopWatch or createStopWatch("Fight Stopwatch", true) -- using the name 'Fight Stopwatch' and starting it automatically
-- some time has passed
stopStopWatch("Fight Stopwatch")
echo("The fight lasted for " .. getStopWatchTime("Fight Stopwatch") .. " seconds.")
resetStopWatch("Fight Stopwatch")
fightStopWatch = fightStopWatch or createStopWatch("Fight Stopwatch")
setStopWatchPersistence("Fight Stopwatch") -- enable this stopwatch to persist over Mudlet sessions
display(getStopWatches()) -- will now show that the stopwatch is persistent