Ulysses

General => Developers Corner => Topic started by: DankNessProvides on April 09, 2016, 08:18:29 PM

Title: Random Script errors (read before presuming please)
Post 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"


Code: [Select]
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
Title: Re: Random Script errors (read before presuming please)
Post by: Bytewave on April 09, 2016, 08:34:46 PM
Code: [Select]
LocalPlayer():getDarkRPVar( "money" )is nil somehow. Only thing that's being concatenated.
Title: Re: Random Script errors (read before presuming please)
Post by: DankNessProvides on April 09, 2016, 08:41:38 PM
Code: [Select]
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.
Title: Re: Random Script errors (read before presuming please)
Post by: Buzzkill on April 10, 2016, 12:23:17 AM
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.
Title: Re: Random Script errors (read before presuming please)
Post by: Promptitude on April 10, 2016, 09:02:21 AM
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.
Title: Re: Random Script errors (read before presuming please)
Post by: DankNessProvides on April 11, 2016, 05:40:39 AM
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