Page 1 of 1

switch for arrays

PostPosted: Mon Jan 09, 2012 11:48 pm
by Fojam
is there any way to do something like a switch, but for arrays? like check which value(s) in the array equal(s) one, and then do something different depending on which value(s) equal(s) one?

Re: switch for arrays

PostPosted: Tue Jan 10, 2012 12:40 am
by skydereign
Do you mean to run a switch through a loop like this?
Code: Select all
int array[10] = {0,1,2,3,4,5,6,7,8};
int i;
for(i=0;i<10;i++)
{
    switch(array[i])
    {
        case 0:
        // do something
        break;

        // and the other cases
    }
}


Or perhaps you mean find the subs of the array that are 1, and execute code depending on the place of the array?

Re: switch for arrays

PostPosted: Tue Jan 10, 2012 12:51 am
by Fojam
yeah i was thinking about doing something through a loop but i was hoping for a simpler way. ok well ill just do that.

Re: switch for arrays

PostPosted: Tue Jan 24, 2012 7:14 pm
by extremalyfresh
Do you need to use the code in draw event or can be collision or create event? I was looking for similar code but I will need it probably to loop once only and then stop.

Re: switch for arrays

PostPosted: Tue Jan 24, 2012 8:27 pm
by schnellboot
it can be everywhere