ManeXi Posted August 30, 2016 Share Posted August 30, 2016 I have created this while loop that it should add one number each 1 second until 10 for some reason the script crashes saying: ERROR: Aborting; infinite running script in whileLoopTest local n = 0 while (n <= 10) do if not (isTimer(timer)) then timer = setTimer(function() outputChatBox("Number: "..n) n = n + 1 end, 1000, 1) end end for some reason without timer works well local n = 0 while (n < 10) do n = n + 1 outputChatBox("Number: "..n, root, 255, 0, 0) end So... my question is: Is there any way to delay the while loop actions? Link to comment
Simple0x47 Posted August 30, 2016 Share Posted August 30, 2016 Maybe it's because this statment which doesn't not follow the creation of the timer due to it's existance. I would take a look at the isTimer and try to convert it into a variable. if not (isTimer(timer)) then Try this: local n = 0 local check = isTimer( timer ) while (n <= 10) do if not ( check ) then timer = setTimer(function() outputChatBox("Number: "..n) n = n + 1 end, 1000, 1) end end Or you could make this with a numerical loop. local number = 0 for i = 1, 20 do number = number + 0.5 -- For making it last more. end if number == math.floor( number ) then outputChatBox("Number: ".. n) end Link to comment
GTX Posted August 30, 2016 Share Posted August 30, 2016 (edited) If you want to crash your game, go ahead: local n = 0 local h1, h2, h3 = debug.gethook() debug.sethook(nil) while (n <= 10) do if not (isTimer(timer)) then timer = setTimer(function() outputChatBox("Number: "..n) n = n + 1 end, 1000, 1) end end debug.sethook(_, h1, h2, h3) This should stop the error but will lag your client lol. EDIT: I suppose you want to run timer 10 times? Use it like: local n = 0 timer = setTimer(function() outputChatBox("Number: "..n) n = n + 1 end, 1000, 10) Edited August 30, 2016 by Guest 1 Link to comment
Simple0x47 Posted August 30, 2016 Share Posted August 30, 2016 While is the most laggy thing on MTA :v Link to comment
GTX Posted August 30, 2016 Share Posted August 30, 2016 While is the most laggy thing on MTA :v If used correctly, it can be pretty useful Link to comment
Simple0x47 Posted August 30, 2016 Share Posted August 30, 2016 While is the most laggy thing on MTA :v If used correctly, it can be pretty useful Tell me a correct use of it on MTA Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now