Enter pickup, array must be indexed
#1

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?
Reply
#2

if (pickupid == EnterPickup[0/1])
Reply
#3

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

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

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;
}
Reply
#6

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

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
*/
Reply
#8

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


Forum Jump:


Users browsing this thread: 1 Guest(s)