• HUD Errors
    2 replies, posted
For some reason i get this error: [lua] Hook 'DrawTime' Failed: [@lua\includes\modules\draw.lua:75] bad argument #1 to 'GetTextSize' (string expected, got nil) [/lua] Here's a fragment of the code: [lua] function ReceiveTime( um ) roundtime = um:ReadShort() timetowrite = "Time: " .. string.ToMinutesSeconds(tostring(roundtime)) DrawTime(timetowrite) end usermessage.Hook("SendTime", ReceiveTime) function DrawTime(recTTW) recTTW = timetowrite; --Msg(recTTW); draw.SimpleText(recTTW, "HUDNumber5", ScrW() / 2, 20, Color(255, 0, 0, 255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER) end hook.Add("HUDPaint", "DrawTime", DrawTime) [/lua] If I place a "Msg(recTTW);" line after the "recTTW = timetowrite;" line then a string is printed in the console, so why is it saying recTTW is nil? I suspect it has something to do with timing, but fixing it is beyond me.
[lua] function ReceiveTime( um ) roundtime = um:ReadShort() timetowrite = "Time: " .. string.ToMinutesSeconds(tostring(roundtime)) end usermessage.Hook("SendTime", ReceiveTime) function DrawTime() if timetowrite then draw.SimpleText(timetowrite, "HUDNumber5", ScrW() / 2, 20, Color(255, 0, 0, 255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER) end end hook.Add("HUDPaint", "DrawTime", DrawTime) [/lua]
Thanks man, that worked great!
Sorry, you need to Log In to post a reply to this thread.