DarkBlizz

Game On => Land of AI => STARCRAFT II: WINGS OF LIBERTY => AI Development => Topic started by: hd on March 05, 2010, 03:46:41 PM

Title: Variable Arrays...
Post by: hd on March 05, 2010, 03:46:41 PM
Anyone have a good grasp of how these function in Galaxy?

I've seen a few references to arrays but I'm not sure how to declare them, if you have to explicitly declare the size or if it's dynamic and why they're dotting the ends.

For example: "AreaArray[0].Radius";

Is the . refering to a sub variable of AreaArray[0] or is it calling a function to be run on the value of AreaArray[0]? If it's calling a function, is it array specific?
Title: Re: Variable Arrays...
Post by: Aeg1s on March 05, 2010, 04:58:04 PM
Quote from: hd on March 05, 2010, 03:46:41 PM
Anyone have a good grasp of how these function in Galaxy?

I've seen a few references to arrays but I'm not sure how to declare them, if you have to explicitly declare the size or if it's dynamic and why they're dotting the ends.

For example: "AreaArray[0].Radius";

Is the . refering to a sub variable of AreaArray[0] or is it calling a function to be run on the value of AreaArray[0]? If it's calling a function, is it array specific?


That section you reference is actually strings for access ability data. You can declare and use arrays just like you would in c (although I don't know if you can initialize them).


For example:

static int playerRace[8];


...


if (playerRace[8] == c_raceProtoss) { ...
Title: Re: Variable Arrays...
Post by: SPmac on March 06, 2010, 06:07:15 PM
This is what I figured out so far about arrays

Declaring...

int[2] IntArr;

string[2] StringArr;



Havent found out how to initialize yet... Perhaps this is not possible.
for example like..

//Doesn't seem to be possible

int int1 = 1, int2 = 2;

int[2] IntArray = { int1, int2 }


Assigning... You must assign in a non-global scope


//Declared in Global Scope

int[2] IntArr;
string[2] StringArr;

void MessWithArrays(){

   //Local Scope

   IntArr[0] = 1;

   StringArr[0] = "String";

   
   int ArrIndex = 0;
   while(ArrIndex != 2){

       UIDisplayMessage(PlayerGroupAll(), c_messageAreaSubtitle, StringToText(IntToString(IntArr[ArrIndex])));

       UIDisplayMessage(PlayerGroupAll(), c_messageAreaSubtitle, StringToText(StringArr[ArrIndex]));

       ArrIndex = ArrIndex + 1;

   }
}



If you were to run AI with MessWithArrays() to test, you'll see this text when it is called...

1
0
String
(blank)

IntArray[0] = 1
IntArray[1] (default int initialization 0)
StringArray[0] = "String"
StringArray[1] (default string initialization "")