I'm having trouble getting this timer to display properly, this should convert the variable "time" into 3 seperate variables, one each for milisec, seconds, minutes.
I'm fairly new to LUA so I don't understand why it's throwing me an error on a "draw_seco" saying it's a nil value even though I initialized it in the GM:initialize function.
Could somebody please explain to me what I did wrong?
Thanks in advance! <3
[B]cl_init.lua[/B]
[CODE]include("shared.lua")
function GM:Initialize()
local time = CurTime() // Current time the server has been up
local draw_mili = 0
local draw_seco = 0
local draw_minu = 0
end
function clockhud()
draw.RoundedBox(0,ScrW()-256,20,256-20,64,Color(255,0,0,128))
time = CurTime();
if time >= draw_seco+1 then
draw_seco = draw_seco+1;
end
if draw_seco >= 60 then
draw_minu = draw_minu+1;
draw_seco = draw_seco-60;
end
draw_mili = time-math.Round(time,2)
draw.DrawText(draw_minu..":"..draw_seco..":"..draw_mili,"HUDNumber5",ScrW()-20,20,Color(255,255,255,255),TEXT_ALIGN_RIGHT)
end
hook.Add("HUDPaint","clockhud", clockhud)[/CODE]
[CODE]
[ERROR] gamemodes/skillrace/gamemode/cl_init.lua:14: attempt to perform arithmetic on global 'draw_seco' (a nil value)
1. v - gamemodes/skillrace/gamemode/cl_init.lua:14
2. unknown - lua/includes/modules/hook.lua:82[/CODE]
draw_sec is local to Initialize so it is not available in the clockhud function
-snip-
So how would I allow it to be used in every function? :3