Error: Null pointer referenced (SOLVED)

Started by Nine Toes, Mon 25/06/2007 15:59:22

Previous topic - Next topic

Nine Toes

I got this error when I run my game:
Error: run_text_script1: error -6 running function 'repeatedly_execute':
Error: Null pointer referenced
In Global Script (Line 71)


Here's my script:
(the asterisk is the line where I get the error)
Code: ags

function repeatedly_execute() {
  if (maincharacter == 0){
*     Jactiveitem.Text = cJohn.ActiveInventory.Name;
      Jdescription.Text = item[cJohn.ActiveInventory.ID].description;
  }
}


Basically what I'm trying to do is display an item's description on a GUI label.
Watch, I just killed this topic...

Ashen

Most likely you won't have an Active Inventory item when you first start the game, which is why it kicks out the error. Add a check for that, e.g.:

Code: ags

function repeatedly_execute() {
  if (maincharacter == 0 && cJohn.ActiveInventory != null){
      Jactiveitem.Text = cJohn.ActiveInventory.Name;
      Jdescription.Text = item[cJohn.ActiveInventory.ID].description;
  }
}


You might also add an 'else' so the Labels display "No Item/ No further Information"-type messages when there's no Active item.
I know what you're thinking ... Don't think that.

Nine Toes

Watch, I just killed this topic...

SMF spam blocked by CleanTalk