Switch troubles
#1

Is this a possible working code?
Because im getting a error by compiling i think i might do something wrong...

pawn Код:
new Variable[5];

public OnPlayerPickUpDynamicPickup(playerid, pickupid)
{
    if(pickupid == Variable[]) // line 2801
    {
        switch(pickupid)
        {
            case 0: return 1; //something happens here
            case 1: return 1; //...
            case 2: return 1; //...
            case 3: return 1; //...
            case 4: return 1; //...
        }
    }
    return 1;
}
Код:
(2801) : error 029: invalid expression, assumed zero
Anyone please could take a look at the code and tell me whats wrong?
Thanks, regards.
Reply
#2

you are missing the index between the brackets
Reply
#3

Like:
pawn Код:
if(pickupid == Variable[5])
?
Reply
#4

5 is not a valid index, if you declare an array with the size of 5 you can only use the cells 0 till 4

maybe it helps if you tell me what that check should do
Reply
#5

I guess this is what you wanted to do:
pawn Код:
public OnPlayerPickUpDynamicPickup(playerid, pickupid)
{
    for(new i<0; i<sizeof(Variable); i++) //Loop through the Variable index
    {
        if(pickupid == Variable[i]) //If it is same as the number which is stored in Variable[index]
        {
            switch(i) //switching the index number.
            {
                case 0: return 1;
                case 1: return 1;
                case 2: return 1;
                case 3: return 1;
                case 4: return 1;
            }
        }
    }
    return 1;
}
Try it out.


Jeffry
Reply
#6

The loop should be more like this:
pawn Код:
for(new i; i<sizeof(Variable); i++) //without the "<0"
But it worked, thanks alot that spares me lots of code.
Reply
#7

Eh, mistyped myself. Should be:
pawn Код:
for(new i=0; i<sizeof(Variable); i++) //without the "<0"
=0 instead of <0 for sure. ^^

But without the =0 it works too, because every variable is 0 after creation.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)