Actor Arrays

Game Editor comments and discussion.

Actor Arrays

Postby DilloDude » Mon Apr 03, 2006 11:58 pm

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?
Image
User avatar
DilloDude
 
Posts: 866
Joined: Tue Jan 24, 2006 9:51 am
Location: Nyerellion
Score: 58 Give a positive score

Postby DilloDude » Tue Apr 04, 2006 1:41 am

The other way, of course, would be to have five different variables, but I would prefer to only use one.
Image
User avatar
DilloDude
 
Posts: 866
Joined: Tue Jan 24, 2006 9:51 am
Location: Nyerellion
Score: 58 Give a positive score

Postby DilloDude » Tue Apr 04, 2006 5:57 am

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.
Image
User avatar
DilloDude
 
Posts: 866
Joined: Tue Jan 24, 2006 9:51 am
Location: Nyerellion
Score: 58 Give a positive score


Return to GE - General

Who is online

Users browsing this forum: No registered users and 1 guest