Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: lucasa on Mon 24/03/2008 22:24:46

Title: vars problem
Post by: lucasa on Mon 24/03/2008 22:24:46
hello... i have a problem with this code:

in ROOM1:

state=5
player.changeroom (2);


inROOM2

if player enters in room (after fade in){
if (state==5) dDialog.start();
}



i have exported the variable state... and... if i display its value... i see a 5... but... conversation dDialog not start... ¿what can i do?

thank you.
Title: Re: vars problem
Post by: SSH on Mon 24/03/2008 22:28:57
Are any of the options in that dialog enabled?
Title: Re: vars problem
Post by: lucasa on Mon 24/03/2008 22:31:55
yes.


i am using 2.72 version.

it could be a bug fixed in newer versions?

i need to change version?
Title: Re: vars problem
Post by: Pumaman on Mon 24/03/2008 22:33:38
What if you do this?

if player enters in room (after fade in){

if (state==5)
{
Display("Starting dialog");
dDialog.Start();
}
}

do you see the message?
Title: Re: vars problem
Post by: lucasa on Mon 24/03/2008 22:37:23
NO, i don't see nothing....


but if i put the display before the if... i see.

and... i see state's value is 5!!!!!!
Title: Re: vars problem
Post by: Pumaman on Mon 24/03/2008 22:39:17
if player enters in room (after fade in){

Display("state = %d", state);
if (state==5)
{
Display("Starting dialog");
dDialog.Start();
}
}

Does it display 5?

How have you declared the "state" variable? Is it an "import" in the script header or have you declared it separately in both rooms?
Title: Re: vars problem
Post by: lucasa on Mon 24/03/2008 22:41:46
i have exported state at the end of the global script of the as help says...


state is declared at global header script.


i have tried not to export state ... and import in the room 2... but it doesn't execute.


Title: Re: vars problem
Post by: lucasa on Mon 24/03/2008 23:42:48
in help i see this text:

In order to import the variable, it must have been exported from the global script with the export keyword.

But... if i export... (at the end of the script) with:

export state;   (state have been declared at script header)

and in the room script i write:

import int state        (as help says).

When i compile... i have this error:

variavle state is already defined;


what i do wrong?
Title: Re: vars problem
Post by: lucasa on Tue 25/03/2008 00:22:49
welll i see i have a great problem with visibility of the variables... i have a similar new problem...

ROOM 1
when players enters (after fade in)i
if (state ==1){

state = 2;
Display (%d,state)

}

then i have an event when i look at player:
Display (%d,state)

first display appears as 2

but when i look at player... state appears as... 1!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!


as before... i have exported state variable at the end of global script, and state have been declared at global header.

i cannot import at room script because i have an error "already defined state" if i try it.
Title: Re: vars problem
Post by: Gilbert on Tue 25/03/2008 01:01:36
Quote from: lucasa on Mon 24/03/2008 22:41:46
state is declared at global header script.

If by "global header script" you're talking about the script header, then this is the problem, as this way you're just making duplicated variables called state which are local to each room.

Instead, define the variable state on top of the global script (not the script header) and then export it at the end of the script, like:

int state;

...

export state;


Then, in the script header (yes, the header this time) import the variable:

import int state;


Haven't read your other posts but I suspect they're similar problems.
Title: Re: vars problem
Post by: lucasa on Tue 25/03/2008 01:07:40
thank you very much, that was the problem.

thank you thank you tnank you

:)
Title: Re: vars problem
Post by: Khris on Tue 25/03/2008 09:58:06
And btw, you can export the variable as soon as you've declared it, you don't have to put the export line at the end:
// top of global script
int state;
export state;


It's a bit tidier IMO, but that's personal preference.