Need help from loop expert.

Non-platform specific questions.

Need help from loop expert.

Postby Jagmaster » Sun Jul 10, 2011 11:25 pm

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?
User avatar
Jagmaster
 
Posts: 875
Joined: Sun May 08, 2011 4:14 pm
Location: Not where you think.
Score: 82 Give a positive score

Re: Need help from loop expert.

Postby skydereign » Mon Jul 11, 2011 12:12 am

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++)
{
    //
}
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Need help from loop expert.

Postby Jagmaster » Mon Jul 11, 2011 1:36 am

Ahh, thanks.
I thought there was something wrong with the if line. :D
User avatar
Jagmaster
 
Posts: 875
Joined: Sun May 08, 2011 4:14 pm
Location: Not where you think.
Score: 82 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest