Reading/Writing global variables

Started by CodeJunkie, Fri 06/08/2004 15:37:23

Previous topic - Next topic

CodeJunkie

I have in my game a lift mechanism which spans three rooms (actually the third, top room isn't finished).Ã,  The lift travels through a middle room, which is just a blank room.Ã,  I can make the lift part work and the player move with it, but I'm having trouble setting a lift direction in the middle room.
I've decided that when the lift is activated from the bottom, it sets a variable lift_entry to 0, meaning that it came from the bottom.Ã,  If it is activated at the top it'll be lift_entry = 1.Ã,  The middle screen will have two lift objects, one at the top and one at the bottom.Ã,  When the player enters the middle screen, a script will run.Ã,  If lift_entry = 0, it'll delete the top lift object and set the bottom one and the player moving upwards.Ã,  If lift_entry = 1 it's just the opposite.
A recent topic in the forum covered SetGlobalInt and GetGlobalInt which I weren't aware of.Ã,  I've put these into my script but I don't understand exactly how these global integers work.Ã,  Here's what I have so far:

Bottom screen - Player walks off top screen edge
(Go to middle room)
Run script:

SetGlobalInt(10,0)


Middle screen - Player enters screen (after fadein):
Run script:

GetGlobalInt(10);
if (GlobalInt(10) == 0) {
DisplaySpeech(DARREN,"J");
}
else {
DisplaySpeech(DARREN,"K");
}


I've just made the character say 'J' or 'K' for now.Ã,  'J' for bottom and 'K' for top.
The GlobalInt bit inside the 'if' part is made up, and it won't compile in the script.Ã,  What should I put in there, because this integer doesn't have a name (it's just global integer 10).Ã,  Do I have to assign a name or something?

Thanks in advance.

strazer

It should be

GetGlobalInt(10);
if (GetGlobalInt(10) == 0) {
DisplaySpeech(DARREN,"J");
}
else {
DisplaySpeech(DARREN,"K");
}

But as I see it, you don't even need to set a variable.
You could check which room the player was in before:

if (character[DARREN].prevroom == BOTTOMROOMNUMBERHERE) {
DisplaySpeech(DARREN,"J");
}
else {
DisplaySpeech(DARREN,"K");
}

And why do you need two lift objects in the middle room? Couldn't you just use a single object and move it to the appropriate starting position when the room is loaded?

CodeJunkie

Thanks, that seems to work alright.
I wanted to lifts because I thought that otherwise there would be a quick jitter as the lift moved to the right position, or wouldn't that be seen?
Thanks again for the detailed answer :)

strazer

You're welcome. :)

Yes, if you use the SetObjectPosition function in "Player enters screen (before fadein)", you won't see any "jitter".

SMF spam blocked by CleanTalk