Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Jojowl80 on Sun 09/08/2020 04:07:25

Title: :ObjectOn: Invalid Object specified
Post by: Jojowl80 on Sun 09/08/2020 04:07:25
my game closes with this error message  :ObjectOn: Invalid Object specified
in reference to object 3

Code (ags) Select


function hHotspot1_UseInv()
{
if (player.ActiveInventory == (iLasso))
player.Say("Okay.");
object[1].Visible = true;
sLever.Play();
object[2].Visible = true;
object[3].Visible = true;
sLadder.Play();
object[0].Visible = true;
RestoreWalkableArea(6);

}



I have all 4 objects set to false before the character throws a switch. So why 3 of them work and the other one does not.. I have no idea
Title: Re: :ObjectOn: Invalid Object specified
Post by: Slasher on Sun 09/08/2020 09:23:14
For a start you had two missing braces:

Code (ags) Select

function hHotspot1_UseInv()
{
if (player.ActiveInventory == (iLasso))
{
player.Say("Okay.");
object[1].Visible = true;
sLever.Play();
object[2].Visible = true;
object[3].Visible = true;
sLadder.Play();
object[0].Visible = true;
RestoreWalkableArea(6);
}
}

Also check out your Object ID's..
Title: Re: :ObjectOn: Invalid Object specified
Post by: Matti on Sun 09/08/2020 12:02:38
Yes, doublecheck if there really is an object 3 in the room.

Also, it's better to give objects (and hotspots!) names. The code will be a lot easier to read and you can avoid referencing objects that don't exist.