Page 1 of 1

Actor Arrays

PostPosted: Mon Apr 03, 2006 11:58 pm
by DilloDude
I have just noticed that actor variables can't be arrays. I want an array of five 0/1 integers. I think I can do this with a string, but how can I check just one character of a string?

PostPosted: Tue Apr 04, 2006 1:41 am
by DilloDude
The other way, of course, would be to have five different variables, but I would prefer to only use one.

PostPosted: Tue Apr 04, 2006 5:57 am
by DilloDude
Ok, now I have got two functions to do assign the values to an integer:
Code: Select all
int getT(int i, int values)
{
    int result = 0;
    int mask = 0;
 
    i-=1;
    if (i < 8)
    {
        mask = 1*pow(2,i);
        result = ((values & mask) > 0);
    }

    return result;
}

int setTValues (int i1, int i2, int i3, int i4, int i5)
{
    return
        i1 * pow(2,0) +
        i2 * pow(2,1) +
        i3 * pow(2,2) +
        i4 * pow(2,3) +
        i5 * pow(2,4);
}

So I can say,
Code: Select all
variable = setTValues (1, 0, 0, 1, 1);

to set the variable and
Code: Select all
getT(2, variable)

will return that the second value is 0.