global variables inexplicably linked [solved]

Started by hedgefield, Sat 26/07/2008 15:32:03

Previous topic - Next topic

hedgefield

I don't know how to describe this problem any other way than give you an example, so here goes.

I made a global variable called gvar_wine, which tracks the choices you make in a certain dialog. Suffice to say when you answer positively, its value becomes 1, if negatively it becomes 2.

After that I made a new global variable called gvar_mexican, which tracks whether or not you've encountered a person in the game, and starts the credit sequence when you enter a particular room when its value is 1.

Now, when I activate the gvar_wine dialog, and answer positively then leave the room, the credit sequence starts. Nowhere is gvar_mexican being called, but it still happens. But it does NOT happen if I answer negatively or dont start the dialog at all and leave the room.

And what's even more interesting is when I dont start the dialog at all, but meet the person, thus setting ONLY gvar_mexican to 1, and then start the dialog, the dialog has changed according to if gvar_WINE was also set to 1.

So could it be that the getglobalint somehow calls up the gvar number instead of its name? I dont know, it doesnt make sense, but thats the only thing I can think of to explain this.

I'm using AGS 3.02 SP1 btw.

Khris

Are you using GlobalInts? Like:

Code: ags
#define gvar_wine 1
#define gvar_mexican 2


int a = GetGlobalInt(gvar_wine);

?

If that's the case, I'd say there's an error in the defines and gvar_wine == gvar_mexican.

hedgefield

#2
Hmm maybe I should try that, I've been using the global variables editor to create them. I forgot you can also do it manually like that.

[edit]
Hmm no luck so far. Using SetGlobalInt as definition in the global script doesn't work anymore, and I don't know how to do that whole #define thing, it's not in the manual. So I removed all the global variables from the editor and created them again, but the problem persists.

There is no definition anywhere that could make gvar_wine == gvar_mexican.
The only place I actually edit these variables via SetGlobalInt is by using set-globalint gvar_wine x during one dialog, and in another dialog I call a run-script which among other things sets gvar_mexican to 1. This second dialog does not occur until three rooms after the room where the problem occurs.

[update]
I have two other variables defined besides _wine and _mexican, which are _window and _cellar. I didnt involve them in the testing before, and like the others they have nothing to do with eachother, but testing shows that they suffer from the same problem. gvar_cellar changes to 1 when you move an object in another room, and gvar_window turns to 1 when you exit a certain room via a particular exit.


Bottom line: when I set a value for one global variable, all the other ones assume the same value. Is this a bug in the global variables editor?

monkey0506

#3
You're not using GetGlobalInt and SetGlobalInt are you?

The global variables editor actually creates variables of the specified type. This is different from the "GlobalInt" functions.

You are actually creating two integers named gvar_wine and gvar_mexican.

I tested this, and each variable holds its own value properly.

That is, instead of:

Code: ags
// DO *NOT* DO THIS!
SetGlobalInt(gvar_mexican, 18);


Do this:

Code: ags
// DO THIS!!!
gvar_mexican = 18;


In the first example, you're setting the global int with the ID of the current value of the gvar_mexican variable
(global int 0). So then if you test GetGlobalInt(gvar_wine) where gvar_wine is still set to 0, you're still testing the value of global int 0.

So we can track the values of our variables:

Code: ags
// gvar_wine: 0
// gvar_mexican: 0
SetGlobalInt(gvar_mexican, 18); // same as: SetGlobalInt(0, 18);
// gvar_wine: 0
// gvar_mexican: 0
int gval = GetGlobalInt(gvar_wine); // same as: GetGlobalInt(0);
// gvar_wine: 0
// gvar_mexican: 0
// gval: 18


Again, the global variables editor actually creates global variables. It does NOT create names for global ints. There is a difference.

hedgefield

Right, OK, I can't say that I completely understand what the problem was, but I see now that global variables and global ints are two different things. I removed all references to GetGlobalInt and SetGlobalInt so that it's just gvar_wine = 1; etc, and that seems to work.

I've only recently switched to the OO scripting language of the 3.0 releases from ags 2.62, so I still need to familiarize myself with some of these new methods. The manual isnt very clear on some of these things.

So I guess there is no choice but to use a run-script now if you want to change a variable from a dialog...

Thanks for the help guys.

SMF spam blocked by CleanTalk