Page 1 of 1

Illegal Assignment Operation

PostPosted: Sun Jan 27, 2013 10:46 pm
by EvanAgain
Code: Select all
int Inventory[10][8];

void INVEN_AddItem(Actor* myActor)
{
    if(!Inventory[9][0])
    {
        //ERROR HERE
        Inventory[9] = {0,0,0,0,0,0,0,0};
    }
}

Re: Illegal Assignment Operation

PostPosted: Sun Jan 27, 2013 11:40 pm
by skydereign
You can't do that in C. You can only set an array like that when declaring it. Otherwise you have to set the values manually. Alternatively, you could use memset to clear the array, but even then memset in gE isn't perfectly like the real memset in C.

Re: Illegal Assignment Operation

PostPosted: Mon Jan 28, 2013 12:25 am
by EvanAgain
Oh.. So only structs (and char arrays) can be set like that. So for an Array, I would have to put them in individually to each position. Alright, Thank you! :D Time to try doing this again.

Re: Illegal Assignment Operation

PostPosted: Mon Jan 28, 2013 1:18 am
by skydereign
EvanAgain wrote:So only structs (and char arrays) can be set like that

No, not really. You can't set structs like that, nor can you set char arrays like that. Any setting of variables with the brackets requires you to set it in the initialization (the very spot the variable is declared). You can however set char* kind of like that (using a constant literal string).
Code: Select all
char buffer[30];
char* string;

buffer = "you can't do this";
string = "you can do this"; // because it is a  pointer
// it sets the pointer to a place in memory where "you can do this" is stored
// but it is constant and can't be changed