• Timer Show Everyframe
    4 replies, posted
I created a Label and I want to set the text to be a count down time from 20 to 0. The only think I don't know how to do is to make it work on every frame because vgui shows only once. [lua] WaitTime = 3 remaining = WaitTime-(CurTime()-WaitTime) remain = vgui.Create("DLabel",bottom) remain:SetPos(15,15) remain:SetFont("General") remain:SetTextColor(color_white) remain:SetText("Remaining: "..remaining) remain:SizeToContents() [/lua]
[QUOTE=BoowmanTech;41743146]I created a Label and I want to set the text to be a count down time from 20 to 0. The only think I don't know how to do is to make it work on every frame because vgui shows only once. [lua] WaitTime = 3 remaining = WaitTime-(CurTime()-WaitTime) remain = vgui.Create("DLabel",bottom) remain:SetPos(15,15) remain:SetFont("General") remain:SetTextColor(color_white) remain:SetText("Remaining: "..remaining) remain:SizeToContents() [/lua][/QUOTE] Create the vgui outside of a hook, and make make the remaining variable update in a hook. The vgui shouldnt be closing, afaik.
Just update the text in the DLabel's Think hook. [lua] WaitTime = 3 remaining = WaitTime-(CurTime()-WaitTime) remain = vgui.Create("DLabel",bottom) remain:SetPos(15,15) remain:SetFont("General") remain:SetTextColor(color_white) remain:SetText("Remaining: "..remaining) remain:SizeToContents() remain.Think = function() remain:SetText("Remaining: "..remaining) remain:SizeToContents() end [/lua]
That worked but I had to add "remaining = WaitTime-(CurTime()-WaitTime)" in the Think hook. The problem is that the time is not like 20,19,18,17 because right now it looks like this [img]http://i.imgur.com/uDuwotu.jpg[/img]
[code] WaitTime = 3 StartTime = CurTime() remain = vgui.Create("DLabel",bottom) remain:SetPos(15,15) remain:SetFont("General") remain:SetTextColor(color_white) remain:SizeToContents() remain.Think = function() remaining = WaitTime-(CurTime()-StartTime) remain:SetText("Remaining: "..remaining) remain:SizeToContents() end[/code]
Sorry, you need to Log In to post a reply to this thread.