SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 12/04/2017, 06:27 PM   #1
Admigo
High-roller
 
Admigo's Avatar
 
Join Date: Oct 2010
Location: The Netherlands
Posts: 1,840
Reputation: 297
Default Variable returning wrong number

Hello

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

DEBUG:
Code:
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
__________________
Follow me on Instagram @brandonvanommen
Admigo is offline   Reply With Quote
Old 12/04/2017, 06:38 PM   #2
DarkSkull
Huge Clucker
 
DarkSkull's Avatar
 
Join Date: Aug 2014
Location: Dubai, United Arab Emirates
Posts: 325
Reputation: 43
Default Re: Variable returning wrong number

That is NOT how enums work. Read this: http://forum.sa-mp.com/showthread.php?t=318307

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

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

Put this under OnGameModeInit. Should Work
DarkSkull is offline   Reply With Quote
Old 12/04/2017, 06:38 PM   #3
Vince
Spam Machine
 
Vince's Avatar
 
Join Date: Sep 2007
Location: Belgium
Posts: 10,067
Reputation: 2660
Default Re: Variable returning wrong number

Enum specifiers cannot have default values. They're not variables, they're constants. It's like doing
Code:
#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.
__________________
Vince is offline   Reply With Quote
Old 12/04/2017, 06:58 PM   #4
Admigo
High-roller
 
Admigo's Avatar
 
Join Date: Oct 2010
Location: The Netherlands
Posts: 1,840
Reputation: 297
Default Re: Variable returning wrong number

Quote:
Originally Posted by Vince View Post
Enum specifiers cannot have default values. They're not variables, they're constants. It's like doing
Code:
#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:
Code:
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
Code:
new LastVehicle[MAX_PLAYERS]=INVALID_PLAYER_ID;
But when i tried that with
Code:
new BailInfoPlayerID[MAX_BAILS]=INVALID_PLAYER_ID;
Its returning 0.
You got an explanation for that?
__________________
Follow me on Instagram @brandonvanommen
Admigo is offline   Reply With Quote
Old 12/04/2017, 07:10 PM   #5
BroZeus
High-roller
 
BroZeus's Avatar
 
Join Date: Jan 2014
Location: India
Posts: 1,398
Reputation: 173
Default Re: Variable returning wrong number

Quote:
Originally Posted by Admigo View Post
Thanks for the info. I also tried:
Code:
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
Code:
new LastVehicle[MAX_PLAYERS]=INVALID_PLAYER_ID;
But when i tried that with
Code:
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 Code:
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.
__________________


"Be the change that you wish to see in the world."

Check out my Github profile!
BroZeus is offline   Reply With Quote
Old 12/04/2017, 07:19 PM   #6
Celmir
Little Clucker
 
Celmir's Avatar
 
Join Date: Jun 2016
Location: Everywhere
Posts: 44
Reputation: 3
Unhappy Re: Variable returning wrong number

I could help you, but I'm on my cellphone and you could understand that it's hard to code on a android cellphone.
Celmir is offline   Reply With Quote
Old 12/04/2017, 07:29 PM   #7
Admigo
High-roller
 
Admigo's Avatar
 
Join Date: Oct 2010
Location: The Netherlands
Posts: 1,840
Reputation: 297
Default Re: Variable returning wrong number

But i don't understand why this is working:
Code:
new LastVehicle[MAX_PLAYERS]=INVALID_PLAYER_ID;//Returns 65535
And this is not working:
Code:
new BailInfoPlayerID[MAX_BAILS]=INVALID_PLAYER_ID;//Returns 0
Its the same code.
__________________
Follow me on Instagram @brandonvanommen
Admigo is offline   Reply With Quote
Old 12/04/2017, 07:34 PM   #8
Celmir
Little Clucker
 
Celmir's Avatar
 
Join Date: Jun 2016
Location: Everywhere
Posts: 44
Reputation: 3
Default Re: Variable returning wrong number

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
Celmir is offline   Reply With Quote
Old 12/04/2017, 07:38 PM   #9
DarkSkull
Huge Clucker
 
DarkSkull's Avatar
 
Join Date: Aug 2014
Location: Dubai, United Arab Emirates
Posts: 325
Reputation: 43
Default Re: Variable returning wrong number

Quote:
Originally Posted by Admigo View Post
Thanks for the info. I also tried:
Code:
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
Code:
new LastVehicle[MAX_PLAYERS]=INVALID_PLAYER_ID;
But when i tried that with
Code:
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 Code:
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!
DarkSkull is offline   Reply With Quote
Old 12/04/2017, 08:06 PM   #10
Admigo
High-roller
 
Admigo's Avatar
 
Join Date: Oct 2010
Location: The Netherlands
Posts: 1,840
Reputation: 297
Default Re: Variable returning wrong number

Thanks all for this information. Rep+.
__________________
Follow me on Instagram @brandonvanommen
Admigo is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Warning 219: local variable "number" shadows a variable at a preceding level Mijata Scripting Help 2 04/06/2016 04:14 PM
How to check if there's a number in a string and get that number as a variable okaym8 Scripting Help 14 08/11/2015 02:15 PM
Returning wrong number Yako Scripting Help 4 31/05/2014 11:56 PM
returning wrong id Hornet600 Help Archive 5 31/03/2011 11:44 AM
Returning largest number Danny Help Archive 2 10/02/2011 06:21 PM


All times are GMT. The time now is 08:44 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.