Switch troubles - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Switch troubles (
/showthread.php?tid=258408)
Switch troubles -
OldDirtyBastard - 30.05.2011
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.
AW: Switch troubles -
Nero_3D - 30.05.2011
you are missing the index between the brackets
Re: Switch troubles -
OldDirtyBastard - 30.05.2011
Like:
pawn Код:
if(pickupid == Variable[5])
?
AW: Switch troubles -
Nero_3D - 30.05.2011
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
Re: Switch troubles -
Jeffry - 30.05.2011
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
Re: Switch troubles -
OldDirtyBastard - 30.05.2011
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.
Re: Switch troubles -
Jeffry - 30.05.2011
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.