Where to declare a string array (SOLVED)

Started by bolfar, Mon 21/08/2006 07:58:48

Previous topic - Next topic

bolfar

Hi.

In script for *Look at hotspot* I need to get a random variable from a string array.

Now I declare the array and set all the values each time Look at action takes place, and it works fine, but is there a way to declare the array only once, not every time I click on a hotspot?

In *Look at hotspot* script I only want:

int ran = Random[59];
Display("%s", my_array[ran]);

but ...

String my_array[60];
my_array[0] = "value 1";
my_array[1] = "value 1";
my_array[2] = "value 1";
...

... I want to put somewhere else, just to be declared once and then left alone.

I tried *global script / game_start*, but I can't import a string array (manual also says: You cannot currently import string variables.) I can't use Game.GlobalStrings, because it only provides 50 variables, and I need them elsewhere. And I only need this array in one room.

I tried *First time player enters room* and *Player enters room (before fadein)*, but I get an error "undefined symbol my_array".

So, is there a way to declare the array anywhere else than in *Look a hotspot*?

Thanks

SSH

Well, for sure you can declare it inside a struct, and import the struct. Or you could write a function that gives you the random string value form the global array and import the function.
12

Gilbert

You can import String arrays actually, I just tried it and it worked (with V2.72).
All I did was just something like:

On top of global script (note that teh variables MUST be declared outside of game_start(), otherwise they're local to game_start() function only):
String aa[10];
export aa;

In game_start() of global script:
aa[0]="hi";
aa[1]="hihi";
aa[2]="hihihi";
...

Then in script header:
import String aa[10];

Then I tried displaying the Strings in the room and it worked.
(Depends on your need, if the String array is used in one room only, you really didn't need to declare it in teh global script, just declare it on top of the room's script and set its content in the "player enters room for the first time" event").

About whatever the manual mentioned, sine I'm too lazy to check I can't confirm, but if it just said "You cannot currently import string variables." I won't consider it as something wrong, because as confusing to most new users, it's true that Strings and strings are different in AGS. Actually strings are old limited variable format which just stayed there for compatibility issues. Though of course I think the manual can be updated to reference more on the capability of teh new String format (theer may be info already, I'm just too lazy to read).

bolfar

That was fast!

ThanksÃ,  SSH and Gilbot.

I used Gilbot's solution and it works.

SMF spam blocked by CleanTalk