Enums or not?
#1

enum PlayerInfo
{
ConnectedTime,
AnotherVariable
};
new pInfo[MAX_PLAYERS][PlayerInfo];

OR

new ConnectedTime[MAX_PLAYERS],AnotherVariable[MAX_PLAYERS];

Which variable definition is better?

I ask this because currently i use first method (enum) and i have a variable named "ConnectedTime" like this
pInfo[playerid][ConnectedTime] = gettime(); // This is at login dialog.

I use some math like this:
new anothervar=gettime()-pInfo[playerid][ConnectedTime]
sometimes, anothervar is 0, but this is not the true...
The enums variables are the reason? They can't store big numbers like timestamps?

Sorry for bad english.
Reply
#2

Quote:
Originally Posted by Adi007
Посмотреть сообщение
They can't store big numbers like timestamps?
This is bullshit

In Pawn all integer are 32-Bit Integer

And to the declaration question, it's doesn't matter

You can choose your favourite style
Reply
#3

Ok, thanks.

Now i have another question.
I have a problem which appear only sometimes after the server stayed online more than 24 hours without an restart:
-GeoIP plugin shows at country, ISP and City everytime "unknown".
-I can't add NPCs (some problem with editing npcmodels i think).
-I can't send rcon commands.

Everybody knows why this happens...and when?
Reply
#4

Once your gamemode gets larger and you need to store more variables, I prefer enums because your code is easier to interpret. It all comes down to personal preference.
Reply
#5

Enumerators make the code very organized, at least for me, same if you want to do defintions of something for example:
pawn Код:
enum {
    NUMBER_ONE = 1,
    NUMBER_TWO,
    NUMBER_THREE
}
these three under the enum will get their proper values - number two will get two number three will get three (it's like defining all of them one by one, but I find this easier)

so yeah its personal preference!

I hope I helped any feedback is appreciated!
Reply
#6

PHP код:
NUMBER_ONE 1
Dont do that...because then you change the index...

why you would start with 1...instead of 0?
Reply
#7

Ok guys thanks for answers but try answer this please:

Now i have another question.
I have a problem which appear only sometimes after the server stayed online more than 24 hours without an restart:
-GeoIP plugin shows at country, ISP and City everytime "unknown".
-I can't add NPCs (some problem with editing npcmodels i think).
-I can't send rcon commands.

Everybody knows why this happens...and when?
Reply
#8

The point was to change the index to have correct values for defines
Reply
#9

Quote:
Originally Posted by Adi007
Посмотреть сообщение
Ok guys thanks for answers but try answer this please:

Now i have another question.
I have a problem which appear only sometimes after the server stayed online more than 24 hours without an restart:
-GeoIP plugin shows at country, ISP and City everytime "unknown".
-I can't add NPCs (some problem with editing npcmodels i think).
-I can't send rcon commands.

Everybody knows why this happens...and when?
bumb for this... (DON'T answer for enums anymore).
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)