1value required as left operand of assignment

This is the code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
void pickupitem(int item)
{
     bool slotfound = false;
     for (int i = 0; i == itemcount && slotfound = true;)
     {
          if (playeritems[i][0] == 0)
          {
                slotfound = true;
                slot = i;
                //rest of code to put an item into the slot found
          }

          else
               i ++;
     }
}


This is a simple for loop that is supposed to find the first empty item slot in the player's inventory.

itemcount is an int that keeps track of how many items there are in the player's inventory.
slotfound = true;

You need == here.
Last edited on
No, you simply need to write slotfound
However you understand it backwards, the loop executes if the condition is meet.
for(int K=0; K<itemcount and not slotfound; )

Still, that flag is not needed, as you could just break the loop or return from the function
Well, I added the other '=' in and now there is no error. And thanks ne555, now it doesn't keep skipping the loop. I had thought that it would do the actions until the conditions were met.
Topic archived. No new replies allowed.