Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: deltree on Mon 25/04/2005 00:05:59

Title: script and variables [SOLVED]
Post by: deltree on Mon 25/04/2005 00:05:59
Hi,
I'm sorry for asking suh a basic question, what is more, I keep asking a lot of question these days:
Here is my problem:

I've got a  variable "noblague" that is modified in the "repetedly execute" script, it's linked to a timer, so this variable is modified every 5 seconds. (I simplify)
I know the variable "noblague" actually changes, because in the "repetedly execute" script, I've placed some "displayspeech" to check it (I don't know any other way to check the state of a value, is there any?)

But now, I need to check in another script (and interaction script) the value of the "noblague" variable.
I need to do this:

if (noblague==1) {
   DisplaySpeech(3,"it works, noblague=1.");
}
(I simplify again)

It just doesn't work. Well, it compiles, the game runs, but it seem that the script considers noblague=0 all the time.

I feel confused about the scripts. there are a lot of place to put scripts in, and I just don't know how they mix together in the end, and which one comes priority.

I hope someone understood my question and could help me about this.
Title: Re: script and variables
Post by: Ashen on Mon 25/04/2005 00:11:30
What's the repeatedly_execute script? Is is possible you've changed noblague again (back to 0, or to a higher number)?

Whay if you try:

if (noblague != 0) {
  DisplaySpeech (3, "It worked.");
}


Or just :

DisplaySpeech (3, "noblague = %d", noblague);

For testing purposes.
Title: Re: script and variables
Post by: strazer on Mon 25/04/2005 04:05:57
Where have you put the declaration of the variable (int noblague)?
And what interaction is it (object/character/hotspot/item)?
Title: Re: script and variables
Post by: TerranRich on Mon 25/04/2005 05:18:49
Check here for tips: http://bfaq.xylot.com/#coding01
Title: Re: script and variables
Post by: deltree on Mon 25/04/2005 10:10:09
to ashen:

thanx for the tips (DisplaySpeech (3, "noblague = %d", noblague);) didn't know how to display a variable. will be usefull.
Here is where I go to  the repetedly execute script:

(http://superdeltree.free.fr/expic/repeat.jpg)

to strazer:
Where have you put the declaration of the variable (int noblague)?

in the main header (CTRL+H)

And what interaction is it (object/character/hotspot/item)?
It's a "talk to character"

TerranRich
thanx for the link, didn't knew that one. It's possible that it can solve my problem, but I can't test it now.
I might have something to do with "import global variable!!"
Title: Re: script and variables
Post by: strazer on Mon 25/04/2005 10:31:26
Quotein the main header (CTRL+H)

If you declare a variable in the main script header, seperate variables will be created for the global script and for each room.

To access a variable defined in the global script from inside room scripts, you have to export it first, then import it into the room script where you need it or in the main script header to make it accessible from all room scripts.
Character interactions are handled in the global script, so you wouldn't need to export/import it just for that.
So do


// main global script

int noblague;
export noblague;


and


// room script

import int noblague;
// now this room script (rep_ex) has access to the variable defined in the global script


or


// main script header

import int noblague;
// variable is now accessible from ALL rooms
Title: Re: script and variables
Post by: Ashen on Mon 25/04/2005 11:01:57
QuoteHere is where I go to  the repetedly execute script:

Actually, I meant what's in the rep_ex script. You said noblague is modified every 5 seconds, on a timer - what code are you using?

Although, it sounds like strazer's right, and you've just declared noblague in the wrong place.
Title: Re: script and variables
Post by: deltree on Mon 25/04/2005 14:10:17
Quote from: Ashen on Mon 25/04/2005 11:01:57
QuoteHere is where I go to  the repetedly execute script:

Actually, I meant what's in the rep_ex script. You said noblague is modified every 5 seconds, on a timer - what code are you using?

Although, it sounds like strazer's right, and you've just declared noblague in the wrong place.

lol, sorry about it!
Actually, the code is quite long, but I've got the explanation, it's about the place where the variables are.