Having trouble with boolean (solved)

Started by Dark Link, Fri 11/12/2009 23:18:31

Previous topic - Next topic

Dark Link

Hi all,

I'm trying to use an inventory item on a character so that once the character has this item the player can go to another room.

The editor doesn't recognise that the character has the item though.

I kind of get why it doesn't work (I've set the bool in both room and global script as it's the only way i can get the game to run, if i remove it from room script it has the error
Code: ags
undefined symbol: GivenTicket
)

Anyway, here's my code:

Global Script:

Code: ags
bool GivenTicket = false;

function cSquirrel_UseInv() //Use the train ticket on the squirrel
{
  if (cPlayer.ActiveInventory == iTicket) //If the player uses the ticket on the squirrel then run the following function
    {
      GivenTicket = true; //Sets the boolean variable to true
      dCSquirrelTicket.Start();
    }
}


Room Script:

Code: ags
bool GivenTicket = false; //Is this line the problem?

function hTrainDoor_Interact()
{
  if (GivenTicket)
    {
      cPlayer.ChangeRoom(2);
  }
  else
    {
      Display ("You must present your ticket to the conductor before proceeding.");     
    }
}



Thanks
"That's not a novel, it's the scribblings of a retard"

monkey0506

The reason you're having that problem is because you're not copying the existing variable into the room script. You're defining a new variable with the same name.

There's a couple of different ways this can be handled depending on what version of AGS you're using. The old way of doing this is:

Code: ags
// GlobalScript.ash
import bool GivenTicket; // this will copy the variable into room and dialog scripts

// GlobalScript.asc
bool GivenTicket = false;
export GivenTicket; // this allows the variable to be imported to other scripts


Remove the "bool GivenTicket" line from your room script entirely and just use the variable normally as you would in the global script.

The newer way of doing this uses the Global Variables pane in the editor (I forget which version of AGS this was but I think maybe 3.1.2 was the first to have it). If you don't see "Global Variables" in the same list with Sprites, Characters, GUIs, Scripts, etc. then just use the older method. If you do have it you can open the pane, right click, and define your variable there. That way it will automatically handle the import/export business for you, and it will be available to all of your scripts.  ;) (if you do this, remove every definition of "bool GivenTicket" from your scripts)

Dark Link

"That's not a novel, it's the scribblings of a retard"

monkey0506

You're welcome! Good luck with everything and let us know if you need any further help.  :=

SMF spam blocked by CleanTalk