• Help: timer.Simple?
    16 replies, posted
When I use this it doesn't wait 5 seconds at all. What am I doing wrong? [CODE]timer.Simple( 5, function() a[0] = a[1] end) timer.Simple( 5, function() a[1] = a[2] end)[/CODE] EDIT: I'm trying to assign a new value to table 'a'.
Well, you could, for instance, show us your whole code so we can put it into context and point out your obvious flaws.
I'm only trying to assign a variable within a timer. Is there a better way?
[QUOTE=gary23548;42393553]I'm only trying to assign a variable within a timer. Is there a better way?[/QUOTE] where is the full code, if that is all you have so far it's going to throw errors back
[QUOTE=gary23548;42393553]I'm only trying to assign a variable within a timer. Is there a better way?[/QUOTE] Well for one, I don't see why you're splitting your operations into 2 functions. There's not much more to say. So far we only know that what you're doing [I]"doesn't work"[/I], but there's nothing from about the 2 lines in the OP apart from the variable 'a' that is missing, but I suppose you defined it in your full code which is again why we need to see your full code.
It's for a custom chatbox. All it's doing is sliding the variable from different "slots" on the screen. I'm using a PaintHUD hook for surface.drawtext. I only want to know is how to redefine a table within a timer.Simple() function. [CODE] local i = 0 a = {} a[0] = "" a[1] = "" a[2] = "" a[3] = "player died" -- Test while i > 1 do timer.Simple( 5, function() a[0] = a[1] end) timer.Simple( 5, function() a[1] = a[2] end) timer.Simple( 5, function() a[2] = a[3] end) end[/CODE]
[QUOTE=gary23548;42393717][CODE] local i = 0 a = {} a[0] = "" a[1] = "" a[2] = "" a[3] = "player died" -- Test while i > 1 do timer.Simple( 5, function() a[0] = a[1] end) timer.Simple( 5, function() a[1] = a[2] end) timer.Simple( 5, function() a[2] = a[3] end) end[/CODE][/QUOTE] You're running a loop based on the condition if the variable "i" is bigger than 1, which it isn't because you just set it to 0. This is why you always post the full code...
[QUOTE=EvacX;42393766]You're running a loop based on the condition if the variable "i" is bigger than 1, which it isn't because you just set it to 0. This is why you always post the full code...[/QUOTE] The code isn't the problem. I know that it's a endless loop. I'm only trying to define a table within the timer.Simple() function.
[QUOTE=gary23548;42393780]The code isn't the problem. I know that it's a endless loop. I'm only trying to define a table within the timer.Simple() function.[/QUOTE] It isn't an endless loop... the loop never runs because i is never greater than 1.
[QUOTE=MakeR;42393797]It isn't an endless loop... the loop never runs because i is never greater than 1.[/QUOTE] Ok, that's my bad. [CODE]local i = 0 a = {} a[0] = "" a[1] = "" a[2] = "" a[3] = "player died" -- Test while i < 1 do timer.Simple( 5, function() a[0] = a[1] end) timer.Simple( 5, function() a[1] = a[2] end) timer.Simple( 5, function() a[2] = a[3] end) end[/CODE]
What is actually happening? Are the timers running at all? How are you checking if they are running?
Basically, it displays a text on the screen. [CODE]local IsAlive = 1 a = {} a[0] = "" a[1] = "" a[2] = "" a[3] = "" a[4] = "" a[5] = "" local i = 0 local x = (ScrW() / 2) - 500 local y = (ScrH() / 2) + 200 function UpdateList() if !LocalPlayer():Alive() and IsAlive == 1 then IsAlive = 0 a[5] = "player died" elseif LocalPlayer():Alive() then IsAlive = 1 end timer.Simple( 5, function() a[0] = a[1] end) timer.Simple( 5, function() a[1] = a[2] end) timer.Simple( 5, function() a[2] = a[3] end) timer.Simple( 5, function() a[3] = a[4] end) timer.Simple( 5, function() a[4] = a[5] end) timer.Simple( 5, function() a[5] = "" end) end hook.Add( "HUDPaint", "Display_custom", function() draw.DrawText( a[5], "Trebuchet24", x, y, Color( 255, 100, 100, 255 ), 1 ) draw.DrawText( a[4], "Trebuchet24", x, y+20, Color( 255, 100, 100, 255 ), 1 ) draw.DrawText( a[3], "Trebuchet24", x, y+40, Color( 255, 100, 100, 255 ), 1 ) draw.DrawText( a[2], "Trebuchet24", x, y+60, Color( 255, 100, 100, 255 ), 1 ) draw.DrawText( a[1], "Trebuchet24", x, y+80, Color( 255, 100, 100, 255 ), 1 ) draw.DrawText( a[0], "Trebuchet24", x, y+100, Color( 255, 100, 100, 255 ), 1 ) end) hook.Add( "Think", "AddList",UpdateList)[/CODE]
my eyes
[QUOTE=Johnny Guitar;42393947]my eyes[/QUOTE] I'd take a screenshot, but the text won't stay more than half a second.
[QUOTE=gary23548;42393914]Basically, it displays a text on the screen. [CODE]local IsAlive = 1 a = {} a[0] = "" a[1] = "" a[2] = "" a[3] = "" a[4] = "" a[5] = "" local x = (ScrW() / 2) - 500 local y = (ScrH() / 2) + 200 function UpdateList() if !LocalPlayer():Alive() and IsAlive == 1 then IsAlive = 0 a[5] = "player died" elseif LocalPlayer():Alive() then IsAlive = 1 end timer.Simple( 5, function() a[0] = a[1] end) timer.Simple( 5, function() a[1] = a[2] end) timer.Simple( 5, function() a[2] = a[3] end) timer.Simple( 5, function() a[3] = a[4] end) timer.Simple( 5, function() a[4] = a[5] end) timer.Simple( 5, function() a[5] = "" end) end hook.Add( "HUDPaint", "Display_custom", function() draw.DrawText( a[5], "Trebuchet24", x, y, Color( 255, 100, 100, 255 ), 1 ) draw.DrawText( a[4], "Trebuchet24", x, y+20, Color( 255, 100, 100, 255 ), 1 ) draw.DrawText( a[3], "Trebuchet24", x, y+40, Color( 255, 100, 100, 255 ), 1 ) draw.DrawText( a[2], "Trebuchet24", x, y+60, Color( 255, 100, 100, 255 ), 1 ) draw.DrawText( a[1], "Trebuchet24", x, y+80, Color( 255, 100, 100, 255 ), 1 ) draw.DrawText( a[0], "Trebuchet24", x, y+100, Color( 255, 100, 100, 255 ), 1 ) end) hook.Add( "Think", "AddList",UpdateList)[/CODE][/QUOTE] First of all you're failing to localize the function "UpdateList" and the table "a". Second, your logic is terribly flawed. Every "Think" you're creating 6 timers that last 5 seconds each (something like a hundred times a second-ish). So basically, when 5 seconds has passed from that script being run, you'll have 6 timer functions running a hundred-ish times per second.
Alright, thanks. I see what you mean.
Use this instead [url]http://wiki.garrysmod.com/page/timer/Create[/url] You can have a 5 second wait that loops endlessly.
Sorry, you need to Log In to post a reply to this thread.