Can global ints be arrays?

Started by Matti, Mon 12/01/2009 19:57:34

Previous topic - Next topic

Matti

It seems that gobal ints can't be arrays. Is that true? That would be a pity.

Khris

Technically speaking, the GlobalInts are an array of 500 ints.
If you want a global array, just use the usual method:

Code: ags
// 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.

Trent R

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
To give back to the AGS community, I can get you free, full versions of commercial software. Recently, Paint Shop Pro X, and eXPert PDF Pro 6. Please PM me for details.


Current Project: The Wanderer
On Hold: Hero of the Rune

Matti

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..

Khris

You can do:

Code: ags
import int bla[10], String text;
// and
export bla, text;

MiteWiseacreLives!

Where in the script do you declare and export the Global Int Array?

Crimson Wizard

#6
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

int MyGlobalArr[100];

Then export it in the same place:
Code: ags

export MyGlobalArr;

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

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?

MiteWiseacreLives!

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.

Crimson Wizard

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.

SMF spam blocked by CleanTalk