About arrays - 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)
+--- Thread: About arrays (
/showthread.php?tid=553612)
About arrays -
xeon_inside - 30.12.2014
Hello everyone , i'm trying to make pickups storing them in a array
Example :
pawn Код:
new variable[10];
public OnGameModeInit()
{
variable[0] = CreatePickup(0,1,0,0,0,-1);
return 1;
}
I'm adding to each one a function using the statement switch but as far i know i can't use arrays in switch.. is there another way to do this?
pawn Код:
public OnPlayerPickUpPickup(playerid, pickupid)
{
switch(variable[])
{
case 0:
{
//
}
case 1:
{
//
}
case 2:
{
//
}
}
return 1;
}
Thanks!.
Re: About arrays -
PowerPC603 - 30.12.2014
You can't do this with a switch-case statement.
You can however loop through your array and search for the pickupid.
Eventually you could use a switch-case after the loop, as soon as you find the index in your array.
pawn Код:
public OnPlayerPickUpPickup(playerid, pickupid)
{
new index;
for (index = 0; index < sizeof(variable); index++)
{
if (variable[index] == pickupid)
{
// You can do something here
// Then end the search through the array, as the pickup was found
// The For-loop will be exited, but "index" will still hold the value where the pickup was found
break;
}
}
// Here, "index" still holds the index of your array where the pickup was found, and can be used by a switch-case statement
switch(index)
{
case 0:
{
//
}
case 1:
{
//
}
case 2:
{
//
}
}
return 1;
}
Respuesta: About arrays -
xeon_inside - 30.12.2014
Thank you PowerPC that was all i need!
+REP.