Raised This Month: $32 Target: $400
 8% 

Solved Enum's


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
LearninG
Senior Member
Join Date: Apr 2019
Location: Iran
Old 08-31-2019 , 02:13   Enum's
Reply With Quote #1

Hi,
why would this have errors ? :
PHP Code:
#include <amxmodx>

enum _:PlayerInfo
{
    
Player_Name[32] ,
    
Player_Authid[35]
}

new 
g_PlayerData33 ] [ PlayerInfo ]

public 
plugin_init()
{
    
register_clcmd("say /test" "test")
}

public 
test(id)
{
    new 
eInfo[g_PlayerData// difference
    
get_user_name(id eInfo[Player_Name] , charsmax(eInfo[Player_Name]))
    
get_user_authid(id eInfo[Player_Authid] , charsmax(eInfo[Player_Authid]))
    
    
client_print(id print_chat "Your name is : %s" eInfo[Player_Name])
    
client_print(id print_chat "Your steamid is : %s" eInfo[Player_Authid] )

Quote:
error 008: must be a constant expression; assumed zero
error 017: undefined symbol "eInfo"
warning 215: expression has no effect
error 001: expected token: ";", but found "]"
error 029: invalid expression, assumed zero
fatal error 107: too many error messages on one line
however this one compiles and works fine in game.

PHP Code:
#include <amxmodx>

enum _:PlayerInfo
{
    
Player_Name[32] ,
    
Player_Authid[35]
}

new 
g_PlayerData33 ] [ PlayerInfo ]

public 
plugin_init()
{
    
register_clcmd("say /test" "test")
}

public 
test(id)
{
    new 
eInfo[PlayerInfo// difference 
    
get_user_name(id eInfo[Player_Name] , charsmax(eInfo[Player_Name]))
    
get_user_authid(id eInfo[Player_Authid] , charsmax(eInfo[Player_Authid]))

    
client_print(id print_chat "Your name is : %s" eInfo[Player_Name])
    
client_print(id print_chat "Your steamid is : %s" eInfo[Player_Authid] )

Quote:
warning 203: symbol is never used: "g_PlayerData"
Header size: 256 bytes
Code size: 404 bytes
Data size: 240 bytes
Stack/heap size: 16384 bytes
Total requirements: 17284 bytes

1 Warning.
Done.
[Finished in 0.3s]
so if we do not need this here , where we will need it ?
PHP Code:
new g_PlayerData33 ] [ PlayerInfo 

Last edited by LearninG; 08-31-2019 at 04:10. Reason: solved
LearninG is offline
E1_531G
Senior Member
Join Date: Dec 2017
Old 08-31-2019 , 02:44   Re: Enum's
Reply With Quote #2

g_PlayerData is an array, and PlayerInfo is an enum.
You cannot create an array using other array as dimension.

Quote:
so if we do not need this here , where we will need it ?
you need it here:
Quote:
get_user_name(id , g_PlayerData[id][Player_Name] , charsmax(g_PlayerData[][Player_Name]))
now you have player's name in this global array, and you can use it anywhere you need it.
__________________
My English is A0
E1_531G is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 08-31-2019 , 03:15   Re: Enum's
Reply With Quote #3

You are getting those errors because you are trying to declare an array size with a non constant value/uncomplete memory address of the var, declaring an array size should be done with pre defined size so the compiler would know what size it should be assigned for.

Note:
Also declaring global array variables should always be in the first of the script and thier sizes before them
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 08-31-2019 at 03:18.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
LearninG
Senior Member
Join Date: Apr 2019
Location: Iran
Old 08-31-2019 , 04:09   Re: Enum's
Reply With Quote #4

Quote:
Originally Posted by E1_531G View Post
g_PlayerData is an array, and PlayerInfo is an enum.
You cannot create an array using other array as dimension.

Quote:
so if we do not need this here , where we will need it ?
you need it here:
Quote:
get_user_name(id , g_PlayerData[id][Player_Name] , charsmax(g_PlayerData[][Player_Name]))
now you have player's name in this global array, and you can use it anywhere you need it.
works , thanks.


Quote:
Originally Posted by Natsheh View Post
Note:
Also declaring global array variables should always be in the first of the script and thier sizes before them
like this ?
PHP Code:
#define MAX_PLAYERS   32

enum _:PlayerInfo
{
    
Player_Name[32] ,
    
Player_Authid[35]
}

new 
g_PlayerData[MAX_PLAYERS 1] [ PlayerInfo 
or


PHP Code:
#define G_PLAYER_DATA_SIZE  33

enum _:PlayerInfo
{
    
Player_Name[32] ,
    
Player_Authid[35]
}

new 
g_PlayerData[G_PLAYER_DATA_SIZE] [ PlayerInfo 

Last edited by LearninG; 08-31-2019 at 04:17.
LearninG is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 08-31-2019 , 10:33   Re: Enum's
Reply With Quote #5

Either technically works but I prefer the first since it indicates what you are holding in the array. MAX_PLAYERS is used across the majority of plugins and everyone knows what it corresponds to. G_PLAYER_DATA_SIZE does not tell the same story.
__________________
Bugsy is offline
Reply



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

Forum Jump


All times are GMT -4. The time now is 23:33.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode