Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: FinalSin on Mon 24/07/2006 20:08:18

Title: Undefined Symbol
Post by: FinalSin on Mon 24/07/2006 20:08:18
I hate posting here. Moreso now that I've learnt a bit of java, because firstly, I think "You really should be able to work this one out." and secondly, I'm sure there is a hidden section of the manual or this website where all of these things are. I searched - I promise!

It's simple, so I know there's a solution.

I've got a character. When you talk to this character, I want it to run a script to check the status of a particular variable. So I've got this:

  // script for Character 4 (Barkeep): Talk to character
character[EGO].Walk(60, 130, eBlock);
if(Fez == 0)
{
RunDialog(1);
}
else
{
RunDialog(5);
}
}
#sectionend character4_a  // DO NOT EDIT OR REMOVE THIS LINE


It tells me that Fez is not defined. I know what this means from java - it means I haven't initialised the variable. But I don't know where to. I've put it right up at the start (at Run When Game Starts), but that isn't going it. I know this is obvious, and I'm sorry, but it's now a wall in my way...
Title: Re: Undefined Symbol
Post by: monkey0506 on Mon 24/07/2006 20:28:34
AGS doesn't have static variables...right now.

If you want to use the variable throughout your game you can define it, outside of all functions, in the global script, and import it in the script header:

// main global script
// put these lines in the global script:
int Fez;
export Fez;

// main script header
//put this line in the script header:
import int Fez;


If you only need it for one room, you can define it at the top of the room script.  Or if you only need it for one function, you could define it inside of that function.
Title: Re: Undefined Symbol
Post by: FinalSin on Mon 24/07/2006 20:35:08
I think (I can't even believe I'm saying this, I've already got a load of variables, just not one declared like this) that I need it throughout several rooms, so I'm going to use your first suggestion.

What do you mean by "main script"? The Room Script?
Title: Re: Undefined Symbol [Local/Import Conflict]
Post by: FinalSin on Mon 24/07/2006 20:53:33
I'm now being told I can't have a local variable with the same name as an import. I've followed the above advice though.
Title: Re: Undefined Symbol
Post by: monkey0506 on Mon 24/07/2006 20:59:51
By "main script" I meant "global" script. As in, click "Script -> Edit global script...".

BTW, (not that I'm a mod or anything) there's a "Modify" button so you can edit your posts. That way you don't have to double-post. ;)
Title: Re: Undefined Symbol
Post by: strazer on Mon 24/07/2006 21:00:17
Please post your code so we can help you better by pointing out the mistake.

If you're trying to use the global variable in a room script, don't define it again. Remember, it has already been defined in the global script and with the export/import has been made ready to use in your room script.
So if, in your room script function, you have:
  int Fez = 1;
or something, just change it to
  Fez = 1;

But as I said, please post the relevant portions of your code so we can help you better.
Title: Re: Undefined Symbol
Post by: FinalSin on Tue 25/07/2006 13:21:24
Sorry, I'd posted some of it above, here's the new code.

#sectionstart game_start  // DO NOT EDIT OR REMOVE THIS LINE
function game_start() {
      // called when the game starts, before the first room is loaded
     int Fez = 0;
    export Fez;
}

#sectionend game_start  // DO NOT EDIT OR REMOVE THIS LINE


#sectionstart dialog_request  // DO NOT EDIT OR REMOVE THIS LINE
function dialog_request(int parameter) {
  if (parameter == 1)
{
    SetGraphicalVariable("Intro",  1);
}
else
{
  if (parameter == 2)
  SetGraphicalVariable("Booze",  0);
}
}
#sectionend dialog_request  // DO NOT EDIT OR REMOVE THIS LINE


And in the main script header:
import int Fezz;
Though I realise that is in the wrong place.

With all that there, it now tells me that I have an "Invalid export symbol".
Title: Re: Undefined Symbol
Post by: strazer on Tue 25/07/2006 13:26:48

int Fez = 0;
export Fez;


You have to put this outside of any functions, at the very top of the global script.

The moment you define a variable inside a function, it is local to the function and gets destroyed when the function ends, regardless of whether you try to export it or not. But the export keyword doesn't work inside functions anyway, hence the error message.
Title: Re: Undefined Symbol
Post by: FinalSin on Tue 25/07/2006 14:00:41
Solved.

Thankyou so much. I am learning from these mistakes!