define integer
#1

hi,

is it possible to define a dynamic integer?
Like that somehow?

pawn Код:
//lets say i store my number of the players currently in the server in PlayerCount Variable
new integer[PlayerCount];
this gives me error so is there a getaround?

+rep, thanks
Reply
#2

Impossible, even with assembly

The only way I know is it how y_malloc it does, it preserves memory at startup
Reply
#3

pawn is set up with dynamic variable types. You can just create a 'new' variable and make it any type of variable; a string, int, byte.

To make sure it is an int, you can maybe cast it to an int.
Reply
#4

Just use MAX_PLAYERS for the size. It doesn't have to be the exact size of the players currently online.
Reply
#5

Quote:
Originally Posted by SuperViper
Посмотреть сообщение
Just use MAX_PLAYERS for the size. It doesn't have to be the exact size of the players currently online.
Declare your own macro for it. Like MAX_INTEGER.

But i dont know as you need two integers wrapped up in an array. Why do you even need it?
Reply
#6

Quote:
Originally Posted by SuperViper
Посмотреть сообщение
Just use MAX_PLAYERS for the size. It doesn't have to be the exact size of the players currently online.
That is really bad advice. If you have only 4 players online and your server supports 500, you are looping through 496 empty variables and, seeing as it is all single threaded, the server has to complete it before continuing further with the script causing lag.

I know what you are going to say 'that loop will continue in a couple ms'. True, but that shouldn't matter. If you finish your work in 3 hours and you know that you could've saved 2 hours if you just kept score of how many people are actually there, then you save 2 hours. Same goes for the server. The server could've done it in less ms and in those ms could've done something else, serve another player for instance.
Reply
#7

Quote:
Originally Posted by mamorunl
Посмотреть сообщение
That is really bad advice. If you have only 4 players online and your server supports 500, you are looping through 496 empty variables and, seeing as it is all single threaded, the server has to complete it before continuing further with the script causing lag.

I know what you are going to say 'that loop will continue in a couple ms'. True, but that shouldn't matter. If you finish your work in 3 hours and you know that you could've saved 2 hours if you just kept score of how many people are actually there, then you save 2 hours. Same goes for the server. The server could've done it in less ms and in those ms could've done something else, serve another player for instance.
No, it is not. If you want to loop through the online players ONLY, then use foreach - this is what it does in the first place. Although, nobody talked about loops..
Reply
#8

Quote:
Originally Posted by PawnoQ
Посмотреть сообщение
hi,

is it possible to define a dynamic integer?
Like that somehow?

pawn Код:
//lets say i store my number of the players currently in the server in PlayerCount Variable
new integer[PlayerCount];
this gives me error so is there a getaround?

+rep, thanks
Why? I believe that's too advance, when you could redefine MAX_PLAYERS and change the value (500 - default) to the server slot you have, example code below.

pawn Код:
#if defined MAX_PLAYERS
    #undef MAX_PLAYERS
#else
    #define MAX_PLAYERS (30) //For example 30 slots.
#endif
Reply
#9

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
No, it is not. If you want to loop through the online players ONLY, then use foreach - this is what it does in the first place. Although, nobody talked about loops..
Well, what else would you want to do with an array?
Reply
#10

Quote:
Originally Posted by mamorunl
Посмотреть сообщение
Well, what else would you want to do with an array?
Storing data only is enough. It doesn't need to loop through the array's indexes when it's not necessary.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)