Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: marcomix on Sat 21/12/2013 17:06:48

Title: Dynamic global variables
Post by: marcomix on Sat 21/12/2013 17:06:48
Global variables are Static, but I would like it to be Dynamic. How can I?

I have in GlobalScript a variable:
int count=3;

I have in Room1 this function:
function hHotspot1_AnyClick(){
    count++;
    Display("conta %d", count);
    player.ChangeRoom(secondroom);
}

I have in Room2 this function:
function hHotspot1_AnyClick(){
    count++;
    Display("conta %d", count);
    player.ChangeRoom(firstroom);
}

So, in first room:
'count' is 4.

In second room:
'count' is 4

But I would like it to be:
in first room 'count' is 4 and then in second room 'count' is 5. How can I?
Title: Re: Dynamic global variables
Post by: DoorKnobHandle on Sat 21/12/2013 17:11:06
What you want is to import/export your variable, search the manual and/or the forums on how to do that. Hope this helps!
Title: Re: Dynamic global variables
Post by: Khris on Sat 21/12/2013 17:24:17
Did you put
Code (ags) Select
int count=3;
in the header (GlobalScript.ash)?
If you do that, what you get is a separate variable for each room.

Unless you need an array or custom struct variable, just check out the Global Variables pane in the project tree.

Alternatively, like dkh said, you can do this:

Code (ags) Select
// header
import int count;

// main script
int count = 3;
export count;


(Also nothing of this has anything to do with dynamic vs. static, fyi.)