Newbie question about array

 

How do I assign a variable into an array (if even possible)?

The most obvious way doesn't work.

string s = "hello";
string test[]= {s, " sir"};
 

From the documentation on Initialization of variables:

"The list of array elements values must be enclosed in braces. Initializing values omitted are considered as equal to 0. If the initializing array size is not defined, it will be defined by the compiler from the szie of the initializing sequence. Multidimensional arrays are initialized by a one-dimensional sequence, i.e. sequence without additional braces. All arrays, including those declared in the local scope, can be initialized with constants only."

string test[] = {"hello", "sir"};

or

string test[2];
test[0] = "hello";
test[1] = "sir";

You can also use ArrayResize() to resize the first dimension of an array after it has been declared/initialized.

 
I see. Thank you.
Reason: