Illegal Assignment Operation

You must understand the Game Editor concepts, before post here.

Illegal Assignment Operation

Postby EvanAgain » Sun Jan 27, 2013 10:46 pm

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};
    }
}
EvanAgain
 
Posts: 51
Joined: Thu Jan 10, 2013 5:40 pm
Score: 4 Give a positive score

Re: Illegal Assignment Operation

Postby skydereign » Sun Jan 27, 2013 11:40 pm

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

Re: Illegal Assignment Operation

Postby EvanAgain » Mon Jan 28, 2013 12:25 am

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.
EvanAgain
 
Posts: 51
Joined: Thu Jan 10, 2013 5:40 pm
Score: 4 Give a positive score

Re: Illegal Assignment Operation

Postby skydereign » Mon Jan 28, 2013 1:18 am

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


Return to Advanced Topics

Who is online

Users browsing this forum: No registered users and 1 guest

cron