AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   how can i check does array field was already set (https://forums.alliedmods.net/showthread.php?t=63938)

orglee 12-03-2007 22:36

how can i check does array field was already set
 
Hello.
I'm creating a menu which player can disable.
Player settings are being stored in multi-dimensional
Code:
enum E_PLAYER {   menu_on = 1 } new g_players[32][E_PLAYER]
But when player connects to the server this variable isn't set and I want it to be set on 1 or...
I want the plugin to recognize empty var as 1
Now I'm checking it using function below.
Code:
public menuStatusGet(id) {   new out   if(equal(g_players[id][menu_on], "") || g_players[id][menu_on] == 1) {     client_print(id, print_chat, "MENU: its on")     out = 1   } else {     client_print(id, print_chat, "MENU: its off")     out = 0   }   client_print(id, print_chat, "menu_on equals: %d", g_players[id][menu_on])   return out }
It is probably cause I'm using equal to check does its empty.
How should I check it so its will return correct value ?
Regards.

Arkshine 12-03-2007 22:57

Re: how can i check does array field was already set
 
I don't understand why you're using an 'enum()' for that.

new g_players[33]; is sufficient.

And if you want to fill with 1 by default, just do that:

new g_players[33] = { 1, ... };

orglee 12-04-2007 00:53

Re: how can i check does array field was already set
 
Quote:

Originally Posted by arkshine (Post 559643)
I don't understand why you're using an 'enum()' for that.

Darn my bad. I'm using this to store two informations.
enum E_PLAYER {
menu_on = 1,
rifle_page = 2
}
I need to store somehow pagination info about current menu page thats why I'm using enum its not that I'm only storing one info in that array.
Please tell me how can do thing I have written in first post.
edit>
besides I think using enum makes code more clean and understandable
edit>>
And on more thing I know how to set default value for a var but do you know how to set default var for all players in that array, with enum of course ?


All times are GMT -4. The time now is 11:00.

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