counter not working.

Started by police brutality, Wed 02/05/2007 08:49:48

Previous topic - Next topic

police brutality

In the global script, at the top.:

int my_counter5;

in a room at the end of a interaction (that does work):

my_counter5 = 5;

in another room:

if  ( my_counter5 == 5 ) { bunch of stuff

and

if  ( my_counter5 == 0 ) { more stuff


The problem is that the game ALWAYS acts as if my_counter5 == 0. How can I change this?

Ashen

Really obvious thing: Have you exported the int from the Global script, and imported it into the Script Header?
I know what you're thinking ... Don't think that.

police brutality

import / export?? what's that???

Ashen

I'll take that as a 'No', then...
Read the BFAQ (which you should have done already), it's explained there.

The thing that confuses me, though, is why trying to access the variables in Room scripts doesn't cause an error, if you haven't made them Global. Are you re-declaring my_counter5 in each room?
I know what you're thinking ... Don't think that.

police brutality

thanks for the link!

and no I didn't add anything, or maybe I did, can't remember, it's 7 am and I've been up since sunday night.

Khris

If you put the declaration into the global script header, you won't get an error even without im-/exporting it. This'll create an instance of the variable for every room, though, and changing it in one room will leave the others set to 0.

This is probably what you did.

To get one var valid in every room, use
Code: ags
int my_counter5;
export my_counter5;
at the top of the global script, outside any function.
Then put
Code: ags
import int my_counter5;
into the script header.

Note that you won't need the variable type (or []-stuff with arrays) when exporting it, while you'll need type/[] when importing the var.

Ashen

Quote from: KhrisMUC on Wed 02/05/2007 11:21:33
If you put the declaration into the global script header, you won't get an error even without I'm-/exporting it. This'll create an instance of the variable for every room, though, and changing it in one room will leave the others set to 0.

Right, of course. I knew that. ::) Guess I'm a little sleep deprived today, as well.
I know what you're thinking ... Don't think that.

police brutality

Ok, now it's like this:

At the top of the global script:

int my_counter5;
export my_counter5;


In script header.

import int my_counter5;

In a room at the end of a interaction

my_counter5 = 5;

In another room

if  ( my_counter5 == 5 ) { something }

if  ( my_counter5 == 0 ) { something else  }

but the counter is always zero.


Gilbert

#8
Are you sure that the interaction did carry out so the counter was set properly to 5 ?
Add the following test line after setting it to 5 to see if it's working properly:

Display("The counter is %d", my_counter);

Also make sure that it's not reset to 0 in some other scripts.

Last but not least, make sure that there ISN'T a variable named my_counter declared in the rooms' scripts.

police brutality

You are right, it was resetting to 0 somewhere, because I changed the counter's name to "locker" in all the mentioned spots and it worked. Thanks

SMF spam blocked by CleanTalk