• Timer Problem
    4 replies, posted
I have this:[lua] timer.Create("Roundtimer", 1, 0, function() Roundtime = Roundtime + 1 print(Roundtime) end ) [/lua] It adds 1 to Roundtime every second, then so i can check it, it prints to the console. You would expect: [code]0 1 2 3[/code] which is what it used to do. Now however it does this [code]0 0 1 1 2 2 3 3[/code]I don't know what i added to make this happen because i didnt check the console after every change - I also didnt know this could happen. I'm not really sure how to go about fixing this because its not like the function is being ran twice because it prints numbers in pairs (no incrementing). I've also noticed that it seems to print a number about every half second. If anyone has an idea on what is happening, i will be glad to hear it. The only thing i could think of is that 2 timers are being created simultaneously - but this is the only timer in my gamemode (ive checked). Any help will be greatly appreciated. Thanks
I think you may be running this serverside [b]AND[/b] clientside.
The function is in init.lua and the only thing that uses the timer outside of that is in my cl_hud.lua which all i use is a function called GetRoundTime which is: [lua] function GetRoundTime() return Roundtime end [/lua] So i don't see how it would be running on both server and client - do you know a way i can check for certain or better lock it to serverside? P.S I know that function is seems pointless, but ill be adding to it later.
If that code in cl_hud.lua works then you are running the timer both clientside and serverside, unless you are using Usermessages to send Roundtime to the client.
That code is in init.lua, all i have [lua] Status_hud:PaintBar( ... , GetRoundTime( ) ) [/lua] (obviosly without the ... , that was to get rid of the irrelevant info) So are you saying that if I call that function, its creating another timer? I don't see how because all it does is return the value of Roundtime. Edit. I took out where GetRoundTime() was and put Roundtime (which is what GetRoundTime() returns anyway) and i still get this which seems to show that the function isn't creating a new timer. Edit. The timer is running clientside and serverside - i know this because I changed it so i knew it would break and was getting clientside errors and serverside errors. I still don't know what's causing it to run clientside though. Edit. I found out what it is. In my cl_hud.lua i have [code]include( 'init.lua' )[/code] so i can use the Roundtime in the hud and for some reason, this creates the timer again.
Sorry, you need to Log In to post a reply to this thread.