Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: Nine Toes on Mon 25/06/2007 15:59:22

Title: Error: Null pointer referenced (SOLVED)
Post by: Nine Toes on Mon 25/06/2007 15:59:22
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)

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.
Title: Re: Error: Null pointer referenced
Post by: Ashen on Mon 25/06/2007 16:19:24
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.:


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.
Title: Re: Error: Null pointer referenced
Post by: Nine Toes on Mon 25/06/2007 16:27:44
It works.  :)  Thanks.