Undefined Symbol

Started by FinalSin, Mon 24/07/2006 20:08:18

Previous topic - Next topic

FinalSin

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:

Code: ags
  // 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...
The Blue Casket

monkey0506

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:

Code: ags
// 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.

FinalSin

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?
The Blue Casket

FinalSin

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.
The Blue Casket

monkey0506

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. ;)

strazer

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.

FinalSin

Sorry, I'd posted some of it above, here's the new code.

Code: ags
#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


Code: ags
#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:
Code: ags
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".
The Blue Casket

strazer

Code: ags

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.

FinalSin

Solved.

Thankyou so much. I am learning from these mistakes!
The Blue Casket

SMF spam blocked by CleanTalk