vars problem

Started by lucasa, Mon 24/03/2008 22:24:46

Previous topic - Next topic

lucasa

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.

SSH

Are any of the options in that dialog enabled?
12

lucasa

yes.


i am using 2.72 version.

it could be a bug fixed in newer versions?

i need to change version?

Pumaman

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?

lucasa

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!!!!!!

Pumaman

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?

lucasa

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.



lucasa

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?

lucasa

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.

Gilbert

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

int state;

...

export state;


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

import int state;


Haven't read your other posts but I suspect they're similar problems.

lucasa

thank you very much, that was the problem.

thank you thank you tnank you

:)

Khris

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:
Code: ags
// top of global script
int state;
export state;


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

SMF spam blocked by CleanTalk