Ags make confusion with global variables?

Started by scab, Tue 02/07/2013 19:38:11

Previous topic - Next topic

scab

Hi, i have a problem with global variable.

I don't understand.
I created 5 global variables with the global variable interface with names and if I set the value 1 for one variable, all my variable change to the value 1.
Ags act like I have one variable...

It's a bug or it's me?

Thank you.

Crimson Wizard

#1
Can you show your script - how you set variable value and how do you check their new values?
Also, what types are your variables, and what is their initial values?

scab

#2
Ok for example. I have a variable called : map

Everytime you do something you unlock a new location.

Code: AGS
function room_Load()
{
    if (GetGlobalInt(map) == 0) {
    oStation.Visible = false;
    }

    else     if (GetGlobalInt(map) == 1) {
    oStation.Visible = true;
    }
}


I have a other variable called picolo (for a character) when you give him an item, the variable are set to 1.

Code: AGS
function cPicolo_UseInv()
{
if (cCody.ActiveInventory==iBo){
   SetGlobalInt(picolo, 1);
}
}


function cPicolo_Talk()
{
    if (GetGlobalInt(picolo) == 1) {
    dDialog1.Start();
}

else {
  cPicolo.Say("Picolo : ... blablabla");
}
}


Variable are in int.
So, I tryed a lot of things like rename variable v_picolo, or with bool, it didn't work.
I have another variable working exacly like picolo but with another character.
I was not sure at the beginning, but I realize when I tryed to give the item to the second person, the variable was already set to 1 because of the variable : picolo.

So, I tryed to do it with only one variable and I wrote :

Code: AGS
function room_Load()
{
SetGlobalInt(picolo, 0);
}


When I go back to the map, the variable : map is set to 0 and I can't go back in the room.

Crimson Wizard

SetGlobalInt and GetGlobalInt are old functions, and they are not related to "Global Variables" you create in the editor. You may completely forget about them.

You should use your global variables same way as you use any other variables in script, that is:

Code: ags

map = 1;

if (map == 0)

etc


What you did: you were calling Get/SetGlobalInt function, sending your "map" and "picolo" variable's VALUE as a parameter.

scab

Ok, thank but in a dialog I did :
set-globalint 0 1
I can't use a name, I need to use a number... How I know what is the number of the variable?

Crimson Wizard

#5
Quote from: scab on Tue 02/07/2013 21:19:10
Ok, thank but in a dialog I did :
set-globalint 0 1
I can't use a name, I need to use a number... How I know what is the number of the variable?
Dialogs allow to use any script command, but they require you put 1 extra space before them.
Therefore you may set variables same way there, just with 1 space indent:
Code: ags

dialog speech
 map = 1;
more dialog speech

san.daniele

Quote from: scab on Tue 02/07/2013 21:19:10
Ok, thank but in a dialog I did :
set-globalint 0 1
I can't use a name, I need to use a number... How I know what is the number of the variable?

sure you can use a name.
just write this in a dialog (add a space or two before the code if used in a dialog)
(I assume 'picolo' is one of your global variables)

Code: AGS
picolo = 1;


edit: Crimson was faster :)

scab


scab

Yeah, it's what I did with an space, because in the tutorial I used, he said you can just use dialog comand for dialog.. Probably an old version..

Ryan Timothy B

Quote from: scab on Tue 02/07/2013 21:41:00
in the tutorial I used, he said you can just use dialog comand for dialog.. Probably an old version..
What tutorial did you use? Was it linked to the forum? Only asking because if it is we should probably unlink that tutorial.

scab

Quote from: Ryan Timothy on Tue 02/07/2013 21:47:16
What tutorial did you use? Was it linked to the forum? Only asking because if it is we should probably unlink that tutorial.

I don't know if it was linked to the forum... it's a french tutorial I found on google...

You can see by yourself..

But I think it's linked to the AGS french site..

Crimson Wizard

Ryan, in fact there's still 2.72 Tutorial linked on the Wiki page.
Go to: Wiki Main Page -> AGS manual online -> Tutorial.
e.g. http://www.adventuregamestudio.co.uk/wiki/Tutorial_Part_1_-_Creating_the_game
As you may see it shows 2.72 screenshots.

Khris

Just for reference: the variables you created, map and picolo, both had a value of 0.
So this line: SetGlobalInt(picolo, 1); became SetGlobalInt(0, 1); and this expression: GetGlobalInt(map) turned into GetGlobalInt(0).
Thus you were always accessing the first GlobalInt (index: 0), which is why all variables appeared to share the same value.

You could actually do this: map = 0; picolo = 1; some_other_variable = 2, etc. That way your code would have actually worked. Still a bad idea of course.

And any tutorial that recommends to use Set/GetGlobalInt() is either really outdated or was written by somebody who shouldn't write tutorials. Either way, don't use them.

Billbis

Just to point out that other french tutorials mostly up to date exist. Also, there is a french translation of AGS help.
(and even a french edition, of AGS, but it is still in beta.)

Kitai

Quote from: scab on Tue 02/07/2013 21:41:00
Yeah, it's what I did with an space, because in the tutorial I used, he said you can just use dialog comand for dialog.. Probably an old version..
I'm not sure what part of the tutorial you are referring to, but if you have this post in mind, note that Shai-la only presents dialog commands (as you wrote) which are to be distinguished from (regular) script commands called from the dialog script. Also note that these tutorials are a bit out-dated now, they were based on AGS 3.0 or something like this. Still, if you find something incorrect on the French forums, please let me know so that I edit the post.

As Billbis points out, there is a French version of the manual, which explains how to call commands from the dialog script.

scab

Quote from: Khris on Wed 03/07/2013 01:01:57
And any tutorial that recommends to use Set/GetGlobalInt() is either really outdated or was written by somebody who shouldn't write tutorials. Either way, don't use them.

Yeah, I didn't expect the expression could change... Thank for the explanation.

Quote from: Kitai on Wed 03/07/2013 08:24:00
Still, if you find something incorrect on the French forums, please let me know so that I edit the post.

Yeah, I used the part you linked and this part too.

Kitai

Quote from: scab on Wed 03/07/2013 13:23:21
Yeah, I used the part you linked and this part too.
Thx, I will add a warning for the GlobalInts part.

SMF spam blocked by CleanTalk