Ulysses
General => Developers Corner => Topic started by: DankNessProvides on April 09, 2016, 08:18:29 PM
-
I am making a HUD which is now complete and working fine no problems but in single line of code I am getting the error "cl_hud.lua:703: attempt to concatenate a nil value"
draw.DrawText ( "$" .. LocalPlayer():getDarkRPVar( "money" ), "Trebuchet24", ScrW() / 3 + 85, ScrH () - 110, Color(255,255,255,255), TEXT_ALIGN_CENTER, TEXT_ALIGN_TOP)
The error doesn't effect anything but just creates a bunch of script errors with the same error over and over again all I am looking for is a quick answer as to why this code might be creating script errors as I cannot for the life of me figure this out
-
LocalPlayer():getDarkRPVar( "money" )
is nil somehow. Only thing that's being concatenated.
-
LocalPlayer():getDarkRPVar( "money" )
is nil somehow. Only thing that's being concatenated.
That's what is confusing me it just giving me a random error and it's just irritating to see that.
-
Why do you assume its random? Take the error at face value. As ByteWave said, the only thing getting concatenated there is the "money" var value to a literal dollar sign. So... I would start by confirming that LocalPlayer():getDarkRPVar("money") is or is not truly null when it throws the error, by adding a print statement (or your debugging method of choice) immediately before the concat call.
If these errors occur during or immediately after initial spawn, I would assume that the vars haven't fully initialized yet. You should probably be testing and trapping null values.
-
Try checking if the car actually exists before you execute that code, if it doesn't, bail. As its in the hud paint hook it'll just not draw the money until it's not nil.
-
Try checking if the car actually exists before you execute that code, if it doesn't, bail. As its in the hud paint hook it'll just not draw the money until it's not nil.
Thanks man it was simply something I just had to add an if statement to check this knew it was gonna be some little simple fix I couldn't see. :D