• Help with creating delays
    1 replies, posted
Hi, I'm fairly new to Lua and I'm trying to print a message to the chat box with a five second delay. I've figured to use a for loop so it iterates 9 times, but I can't get the delay of 5 seconds, please help. This is what i currently have, missing the delay. [CODE] for secs = 45,0,-5 do chat.AddText(Color(255,0,0) "[WARDEN] It is now War Day, prisoners have" + secs + "before they are KOS. There will be NO LR") end [/CODE] What would be the easiest way for me to use a delay, I looked into os.sleep and it doesn't seem to work well. app:delay didn't work either.
Check out [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/timer/Create]timer.Create[/url]. [lua] timer.Create("timerUniqueName", 5, 9, function () doStuff() end) [/lua] Argument 1 is the unique identifier, argument 2 is the delay, argument 3 is the number of iterations, and argument 4 is the anonymous function with the code you want run.
Sorry, you need to Log In to post a reply to this thread.