SA-MP Forums Archive
Enter pickup, array must be indexed - 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: Enter pickup, array must be indexed (/showthread.php?tid=431923)



Enter pickup, array must be indexed - dominik523 - 20.04.2013

Hey! I want to add to my script pickups, which will be at coordinates where you can enter at the building. When you enter pickup, text draw will show for player. I tried to add something, but I have an error. This is my code:
Код:
new EnterPickup[20];
-------------
OnGameModeInit
EnterPickup[0] = CreatePickup(...)
EnterPickup[1] = CreatePickup(...)
--------------
public OnPlayerPickUpPickup(playerid, pickupid)
{
         if(pickupid == EnterPickup) // here is error
	{
	      Show text draw which I will create later
	}
	return 1;
}
Here is my error:
array must be indexed (variable "EnterPickup")
What do I have to put in my code so I can compare pickupid and EnterPickup?


Re: Enter pickup, array must be indexed - HurtLocker - 20.04.2013

if (pickupid == EnterPickup[0/1])


Re: Enter pickup, array must be indexed - dominik523 - 20.04.2013

k, thanks. How would I put to EnterPickup so it doesn't matter which one is? I mean on all 20 pickups


Re: Enter pickup, array must be indexed - HurtLocker - 20.04.2013

if (pickupid == EnterPickup[0] || pickupid == EnterPickup[1] || pickupid == EnterPickup[2] || ..........)


Re: Enter pickup, array must be indexed - Jessyy - 20.04.2013

Or:
Код:
#define INVALID_PICKUP_ID	-1
new EnterPickup[20] = {INVALID_PICKUP_ID, ...}; //initialize array with "INVALID_PICKUP_ID" value
-------------
OnGameModeInit
EnterPickup[0] = CreatePickup(...);
EnterPickup[1] = CreatePickup(...);
--------------
public OnPlayerPickUpPickup(playerid, pickupid)
{
	for(new i = 0, j = sizeof(EnterPickup); i < j; i++) {
		if(pickupid == EnterPickup[i]) {
			// Show text draw which I will create later
			break; // to stop looking in the array
		}
	}
	return 1;
}



Re: Enter pickup, array must be indexed - dominik523 - 20.04.2013

thanks guys for helping me. Jessyy why do I need to put define invalid pickup id? and initailize it with array?


Re: Enter pickup, array must be indexed - Jessyy - 20.04.2013

Pff:
Код:
new myVariable;
// This tells the system to create a new variable called myVariable, the initial value of this variable will be 0.
// value of myVariable is 0

new myArray[5];
// This tells the system to create an array variable called myArray, the initial value of this array will be 0.
// value of myArray is {0, 0, 0, 0, 0}
This function "CreatePickup" return the ID of the created pickup, -1 on failure (pickup max limit).
So when you use for the first time "CreatePickup" in OnGameModeInit the id of pickups will be:
Код:
EnterPickup[i] = CreatePickup(...); // ID 0
EnterPickup[i] = CreatePickup(...); // ID 1
EnterPickup[i] = CreatePickup(...); // ID 2
EnterPickup[i] = CreatePickup(...); // ID 3
etc..
CASE 1:
Код:
new EnterPickup[5]; // value of this array is 0
-------------
OnGameModeInit
EnterPickup[0] = CreatePickup(...); // ID 0
EnterPickup[1] = CreatePickup(...); // ID 1
--------------
public OnPlayerPickUpPickup(playerid, pickupid) // is called with these values​​: (0, 0)
{
   for(new i; i < 5; i++) {
      if(i == EnterPickup[i]) {
         printf("Playerid %d ... pickuppickup: %d", playerid, i);
      }
   }
   return 1;
}
/*
The output will be:
Playerid 0 ... pickuppickup: 0
Playerid 0 ... pickuppickup: 2
Playerid 0 ... pickuppickup: 3
Playerid 0 ... pickuppickup: 4
*/
CASE 2:
Код:
#define INVALID_PICKUP_ID	-1
new EnterPickup[5] = {INVALID_PICKUP_ID, ...}; // value of this array is {-1, ...}
-------------
OnGameModeInit
EnterPickup[0] = CreatePickup(...); // ID 0
EnterPickup[1] = CreatePickup(...); // ID 1
--------------
public OnPlayerPickUpPickup(playerid, pickupid) // is called with these values​​: (0, 0)
{
   for(new i; i < 5; i++) {
      if(i == EnterPickup[i]) {
         printf("Playerid %d ... pickuppickup: %d", playerid, i);
      }
   }
   return 1;
}
/*
The output will be:
Playerid 0 ... pickuppickup: 0
*/



Re: Enter pickup, array must be indexed - dominik523 - 20.04.2013

nice, got it thank you so much for explaining that to me