Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: scab on Tue 02/07/2013 19:38:11

Title: Ags make confusion with global variables?
Post by: scab on Tue 02/07/2013 19:38:11
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.
Title: Re: Ags make confusion with global variables?
Post by: Crimson Wizard on Tue 02/07/2013 19:52:46
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?
Title: Re: Ags make confusion with global variables?
Post by: scab on Tue 02/07/2013 20:54:59
Ok for example. I have a variable called : map

Everytime you do something you unlock a new location.

Code (AGS) Select
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) Select
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) Select
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.
Title: Re: Ags make confusion with global variables?
Post by: Crimson Wizard on Tue 02/07/2013 21:02:51
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) Select

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.
Title: Re: Ags make confusion with global variables?
Post by: 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?
Title: Re: Ags make confusion with global variables?
Post by: Crimson Wizard on Tue 02/07/2013 21:33:37
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) Select

dialog speech
map = 1;
more dialog speech
Title: Re: Ags make confusion with global variables?
Post by: san.daniele on Tue 02/07/2013 21:36:12
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) Select
picolo = 1;

edit: Crimson was faster :)
Title: Re: Ags make confusion with global variables?
Post by: scab on Tue 02/07/2013 21:38:50
Thank you so much! It's work!
Cya
Title: Re: Ags make confusion with global variables?
Post by: 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..
Title: Re: Ags make confusion with global variables?
Post by: Ryan Timothy B on Tue 02/07/2013 21:47:16
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.
Title: Re: Ags make confusion with global variables?
Post by: scab on Tue 02/07/2013 22:52:05
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.. (http://salon-makers.xooit.com/t507-Sommaire-de-tous-les-tutoriels-pour-AGS.htm)

But I think it's linked to the AGS french site..
Title: Re: Ags make confusion with global variables?
Post by: Crimson Wizard on Tue 02/07/2013 22:59:23
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.
Title: Re: Ags make confusion with global variables?
Post by: Khris on Wed 03/07/2013 01:01:57
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.
Title: Re: Ags make confusion with global variables?
Post by: Billbis on Wed 03/07/2013 07:48:38
Just to point out that other french tutorials mostly up to date exist (http://adventuregamestudio.fr-bb.com/). Also, there is a french translation of AGS help (http://admin.no.uchi.free.fr/dokuwiki-2008-05-05/doku.php).
(and even a french edition (http://adventuregamestudio.fr-bb.com/t2054-ags-322-beta-en-francais#32618), of AGS, but it is still in beta.)
Title: Re: Ags make confusion with global variables?
Post by: Kitai on Wed 03/07/2013 08:24:00
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 (http://adventuregamestudio.fr-bb.com/t120-fonctions-liees-aux-dialogues#744) 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 (http://admin.no.uchi.free.fr/dokuwiki-2008-05-05/doku.php?id=configurer_le_jeu#conversations).
Title: Re: Ags make confusion with global variables?
Post by: scab on Wed 03/07/2013 13:23:21
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 (http://adventuregamestudio.fr-bb.com/t31-fonctions-globales) too.
Title: Re: Ags make confusion with global variables?
Post by: Kitai on Wed 03/07/2013 18:02:58
Quote from: scab on Wed 03/07/2013 13:23:21
Yeah, I used the part you linked and this part (http://adventuregamestudio.fr-bb.com/t31-fonctions-globales) too.
Thx, I will add a warning for the GlobalInts part.