Page 1 of 1

Need help from loop expert.

PostPosted: Sun Jul 10, 2011 11:25 pm
by Jagmaster
Here is the loop. I'm using an array for holding inventory. This loop is for turning on the icons in the menu.
Code: Select all
int i;
for(i=0; i=7; i++)
    {
        if(inv[i]>0)
        { sprintf(astring, "w2.%i", i);//w2 is an actor.
 
            VisibilityState(astring, ENABLE);
        }
    }

I need it to first see if a specific inv (inventory) array is greater than 0, than if it is, then turn the visibility state to enable for the clone with the matching cloneindex (for whichever array is not empty).


Every time I try, I get a runtime error (the line with if(inv>0)[i] so it says). Does anyone know what I'm doing wrong?

Re: Need help from loop expert.

PostPosted: Mon Jul 11, 2011 12:12 am
by skydereign
Well, your for loop is wrong. You have = instead of less than. So each time it tries to run through the loop it will set i to 7, and that will be out of bounds for the array.
Code: Select all
for(i=0; i<7; i++)
{
    //
}

Re: Need help from loop expert.

PostPosted: Mon Jul 11, 2011 1:36 am
by Jagmaster
Ahh, thanks.
I thought there was something wrong with the if line. :D