Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Matti on Mon 12/01/2009 19:57:34

Title: Can global ints be arrays?
Post by: Matti on Mon 12/01/2009 19:57:34
It seems that gobal ints can't be arrays. Is that true? That would be a pity.
Title: Re: Can global ints be arrays?
Post by: Khris on Mon 12/01/2009 20:26:13
Technically speaking, the GlobalInts are an array of 500 ints.
If you want a global array, just use the usual method:

// header

import int gi[1000];

// script

int gi[1000];
export gi;


Note that the import line is the same as the declaration with "import" in front while export needs just the name.
Title: Re: Can global ints be arrays?
Post by: Trent R on Mon 12/01/2009 20:27:38
Like the global vars pane? I don't think so. However, you should be able to make it globally available by exporting it from the global script.

[Edit]: Beat by Khris.

~Trent
Title: Re: Can global ints be arrays?
Post by: Matti on Mon 12/01/2009 20:49:46
Yeah, I used the import-export commands now, but I would have prefered to do that via the global variables pane. Importing and exporting 17 variables (at once) is a bit annoying.

But thanks anyway..
Title: Re: Can global ints be arrays?
Post by: Khris on Mon 12/01/2009 21:17:14
You can do:

import int bla[10], String text;
// and
export bla, text;
Title: Re: Can global ints be arrays?
Post by: MiteWiseacreLives! on Tue 30/10/2012 18:23:01
Where in the script do you declare and export the Global Int Array?
Title: Re: Can global ints be arrays?
Post by: Crimson Wizard on Tue 30/10/2012 19:52:39
Quote from: MiteWiseacreLives! on Tue 30/10/2012 18:23:01
Where in the script do you declare and export the Global Int Array?
Usually you declare array normally in script source (*.asc file) like
Code (ags) Select

int MyGlobalArr[100];

Then export it in the same place:
Code (ags) Select

export MyGlobalArr;

Then re-declare it as import in the script's header (*.ash file) like
Code (ags) Select

import int MyGlobalArr[100];


If you do that in GlobalScript, both GlobalScript and all room scripts will be able to use it.


...now, I feel a little silly, since I practically repeated what Khris said above in this topic... 3 years ago.
Could it be your question was about something different, MiteWiseacreLives?
Title: Re: Can global ints be arrays?
Post by: MiteWiseacreLives! on Tue 30/10/2012 20:18:59
no, this helps to clarify.. was unable to find clear instructions on this.
So would I import the array in the GlobalScript.ash? ( I've not used this script before)
then i can refer to the int's in any room script?
Sorry if these questions seem simple.
Title: Re: Can global ints be arrays?
Post by: Crimson Wizard on Tue 30/10/2012 20:44:52
Quote from: MiteWiseacreLives! on Tue 30/10/2012 20:18:59
So would I import the array in the GlobalScript.ash? ( I've not used this script before)
You declare them as import - yes. Formally speaking, variables are exported from GlobalScript and imported to room scripts, but to do so you declare them as import in GlobalScript.ash. GlobalScript.ash (the script header) - is what is "visible" in room scripts, while GlobalScript.asc is not.

Quote from: MiteWiseacreLives! on Tue 30/10/2012 20:18:59
then i can refer to the int's in any room script?
yes, exactly.