Variable returning wrong number
#1

Hello

I have a problem with my variable.
When i check the variable its returning 0 while it should return 65535(INVALID PLAYER)
Код:
enum BailData
{
	PlayerID=INVALID_PLAYER_ID,
	PlayerArrestID=INVALID_PLAYER_ID,
	PlayerPrice
}
new BailInfo[MAX_BAILS][BailData];
How can i fix this?

DEBUG:
Код:
COMMAND:testbail(playerid,params[])
{
	for(new i; i < MAX_BAILS; i++) 
	{
		printf("NUM:%d PID:%d",i,BailInfo[i][PlayerID]);
	}
}
returns 
NUM:1 PID:0
NUM:2 PID:0
NUM:3 PID:0
NUM:4 PID:0
etc...
PS: This variable has not been set to other values.

Admigo
Reply
#2

That is NOT how enums work. Read this: https://sampforum.blast.hk/showthread.php?tid=318307

And to solve your problem, You can use a loop at set its values.

PHP код:
for (new 0MAX_BAILSi++) {
    
BailInfo[i][PlayerID] = INVALID_PLAYER_ID;
    
BailInfo[i][PlayerArrestID] = INVALID_PLAYER_ID;

Put this under OnGameModeInit. Should Work
Reply
#3

Enum specifiers cannot have default values. They're not variables, they're constants. It's like doing
Код:
#define PlayerID INVALID_PLAYER_ID
You're actually creating an array 65537 times MAX_BAILS cells in size, which is probably reflected in the size of the amx.
Reply
#4

Quote:
Originally Posted by Vince
Посмотреть сообщение
Enum specifiers cannot have default values. They're not variables, they're constants. It's like doing
Код:
#define PlayerID INVALID_PLAYER_ID
You're actually creating an array 65537 times MAX_BAILS cells in size, which is probably reflected in the size of the amx.
Thanks for the info. I also tried:
Код:
new BailInfoPlayerID[MAX_BAILS]=INVALID_PLAYER_ID;
But thats returning 0 also.
So its not working like that either?

EDIT: LastVehicle[playerid] is returning 65535 when i use
Код:
new LastVehicle[MAX_PLAYERS]=INVALID_PLAYER_ID;
But when i tried that with
Код:
new BailInfoPlayerID[MAX_BAILS]=INVALID_PLAYER_ID;
Its returning 0.
You got an explanation for that?
Reply
#5

Quote:
Originally Posted by Admigo
Посмотреть сообщение
Thanks for the info. I also tried:
Код:
new BailInfoPlayerID[MAX_BAILS]=INVALID_PLAYER_ID;
But thats returning 0 also.
So its not working like that either?

EDIT: LastVehicle[playerid] is returning 65535 when i use
Код:
new LastVehicle[MAX_PLAYERS]=INVALID_PLAYER_ID;
But when i tried that with
Код:
new BailInfoPlayerID[MAX_BAILS]=INVALID_PLAYER_ID;
Its returning 0.
You got an explanation for that?
In pawno you can initialize array to default value like this :
PHP код:
new BailInfoPlayerID[MAX_BAILS] = {INVALID_PLAYER_ID, ...}; 
That will not return 0.
However this doesn't works with enums, will work with one dimensional arrays only AFAIK.
Reply
#6

I could help you, but I'm on my cellphone and you could understand that it's hard to code on a android cellphone.
Reply
#7

But i don't understand why this is working:
Код:
new LastVehicle[MAX_PLAYERS]=INVALID_PLAYER_ID;//Returns 65535
And this is not working:
Код:
new BailInfoPlayerID[MAX_BAILS]=INVALID_PLAYER_ID;//Returns 0
Its the same code.
Reply
#8

It's not the same. BailInfoPlayerID[MAX_BAILS] whilst LastVehicles[MAX_PLAYERS] and INVALID_PLAYER_ID is checking playerid or something like that. Kinda confusing when your screen is so small and your phone is crappy. Lmao
Reply
#9

Quote:
Originally Posted by Admigo
Посмотреть сообщение
Thanks for the info. I also tried:
Код:
new BailInfoPlayerID[MAX_BAILS]=INVALID_PLAYER_ID;
But thats returning 0 also.
So its not working like that either?

EDIT: LastVehicle[playerid] is returning 65535 when i use
Код:
new LastVehicle[MAX_PLAYERS]=INVALID_PLAYER_ID;
But when i tried that with
Код:
new BailInfoPlayerID[MAX_BAILS]=INVALID_PLAYER_ID;
Its returning 0.
You got an explanation for that?
Yes I have an explanation for that. Because we mention the condition as < MAX_BAILS. That excludes the last one. To fix this, You should use <=

PHP код:
for (new 0<= MAX_BAILSi++) {
    
BailInfo[i][PlayerID] = INVALID_PLAYER_ID;
    
BailInfo[i][PlayerArrestID] = INVALID_PLAYER_ID;

But remember if MAX_BAILS is set to 500, You will have 501 items because 0 is counted as one. So it's better to just leave it at < MAX_BAILS

To clear your doubts about ENUMS, Refer to the thread I posted. It should help You!
Reply
#10

Thanks all for this information. Rep+.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)