ULX

Author Topic: Random Script errors (read before presuming please)  (Read 2337 times)

0 Members and 1 Guest are viewing this topic.

Offline DankNessProvides

  • Newbie
  • *
  • Posts: 26
  • Karma: -3
Random Script errors (read before presuming please)
« 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

Offline Bytewave

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 718
  • Karma: 116
  • :)
    • My Homepage
Re: Random Script errors (read before presuming please)
« Reply #1 on: April 09, 2016, 08:34:46 PM »
Code: [Select]
LocalPlayer():getDarkRPVar( "money" )is nil somehow. Only thing that's being concatenated.
bw81@ulysses-forums ~ % whoami
Homepage

Offline DankNessProvides

  • Newbie
  • *
  • Posts: 26
  • Karma: -3
Re: Random Script errors (read before presuming please)
« Reply #2 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.

Offline Buzzkill

  • Respected Community Member
  • Full Member
  • *****
  • Posts: 176
  • Karma: 59
    • The Hundred Acre Bloodbath
Re: Random Script errors (read before presuming please)
« Reply #3 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.
« Last Edit: April 10, 2016, 12:32:55 AM by Buzzkill »

Offline Promptitude

  • Newbie
  • *
  • Posts: 9
  • Karma: 1
Re: Random Script errors (read before presuming please)
« Reply #4 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.

Offline DankNessProvides

  • Newbie
  • *
  • Posts: 26
  • Karma: -3
Re: Random Script errors (read before presuming please)
« Reply #5 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