Variable returning wrong number -
Admigo - 12.04.2017
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
Re: Variable returning wrong number -
DarkSkull - 12.04.2017
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 i = 0; i < MAX_BAILS; i++) {
BailInfo[i][PlayerID] = INVALID_PLAYER_ID;
BailInfo[i][PlayerArrestID] = INVALID_PLAYER_ID;
}
Put this under OnGameModeInit. Should Work
Re: Variable returning wrong number -
Vince - 12.04.2017
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.
Re: Variable returning wrong number -
Admigo - 12.04.2017
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?
Re: Variable returning wrong number -
BroZeus - 12.04.2017
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.
Re: Variable returning wrong number -
Celmir - 12.04.2017
I could help you, but I'm on my cellphone and you could understand that it's hard to code on a android cellphone.
Re: Variable returning wrong number -
Admigo - 12.04.2017
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.
Re: Variable returning wrong number -
Celmir - 12.04.2017
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
Re: Variable returning wrong number -
DarkSkull - 12.04.2017
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 i = 0; i <= MAX_BAILS; i++) {
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!
Re: Variable returning wrong number -
Admigo - 12.04.2017
Thanks all for this information. Rep+.