Best way to sleep() ?
Greetings
Sense there doesn't seem to be any built in sleep for x function, I tried the following but had some issues of it never ending for some reason: function sleep() { start_time = GetTime() -- current system time in seconds end_time = start_time + 2 -- 2 seconds later while (end_time > start_time) do -- sleeping end } thats from memory as im not at my wow machine atm, any ideas? thanks |
You need to GetTime() again inside your While loop.
Let me explain a bit. When the function runs, it gets time and stores it in Start_Time. Lets say its 5400. Then it sets the End_Time to 5400 + 2 The loop starts and of course End_Time(5402) is more than Start_Time(5400), so it does your sleeping code and repeats the loop. If your Sleep() function gets called again, it will do that same thing just with slightly higher numbers. End_Time will always be 2 more than Start_Time, always. You need to update Start_Time every time the loop runs or it will always evaluate true and do your sleeping code. Something like this should work for you: Code:
function Sleep() |
Just to make sure, are you tying to implement a sleep function using an empty while loop?
Was your "--Sleeping" just a comment like I think it is or do you actually have some "Sleeping code" like Mulesh implies? |
What exactly is the goal? The code posted here will outright lock your game client until a certain amount of time has passed. Such a function raises some ethical questions, as it can be used to simulate lag in very nasty ways by unscrupulous players; for example, you could run across your graveyard in the Warsong Gulch, hit 'sleep' for 10 seconds, then watch as the enemy team chases the ghost produced by your "lag" off the cliff.
Assuming that's what you want, this would be a function to "sleep" for a variable length of time: Code:
sleep = function(time) |
Yeah sorry guys for not being very clear, my goal was to just have a sleep function I could use to mod wait for a specified period of time on specific functions but when I used my sleep function it would cause the game to "lock up" for the duration.
Thanks for mentioning OnUpdate, I found this blurb on it and it seems to be what i want: http://www.wowwiki.com/HOWTO:_Use_OnUpdate_correct |
Well, within a function you can't have a "wait." There is no definition for sleep that will make this behave the way you describe without locking up your game client:
Code:
talkInTen = function() Code:
local q = { } |
All times are GMT -6. The time now is 01:42 PM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI