21.12.2015, 20:31
Option 1 is best here.
It has no use to re-declare variables every iteration of a loop.
Using "new bank = 1;" actually asks the compiler to reserve some memory, then assign it a starting value.
Since it's already reserved, you don't need to reserve it a second time, or even a third or as many times as you have players.
If you declare variables inside a loop, they're destroyed when you exit the loop, after which you re-enter it again as long as there are players.
With 50 players online, you would reserve memory and destroy it again 50 times for the same purpose.
Doing this with a single integer won't matter much, but if you were to do it with big arrays, you would notice a slowdown.
Second question:
Yes, you can re-use strings as many times as you want inside the same function.
Using "format", it overwrites the entire string so it doesn't matter if you put something inside it already.
Unless you use
This would first put the current contents of "string", put it where the "%s" is located, then append the rest of the given text to it.
The above is comparable to strcat, which is used to merge 2 strings together.
It has no use to re-declare variables every iteration of a loop.
Using "new bank = 1;" actually asks the compiler to reserve some memory, then assign it a starting value.
Since it's already reserved, you don't need to reserve it a second time, or even a third or as many times as you have players.
If you declare variables inside a loop, they're destroyed when you exit the loop, after which you re-enter it again as long as there are players.
With 50 players online, you would reserve memory and destroy it again 50 times for the same purpose.
Doing this with a single integer won't matter much, but if you were to do it with big arrays, you would notice a slowdown.
Second question:
Yes, you can re-use strings as many times as you want inside the same function.
Using "format", it overwrites the entire string so it doesn't matter if you put something inside it already.
Unless you use
pawn Код:
format(string, sizeof(string), "%sSmall message with 30 characters", string);
The above is comparable to strcat, which is used to merge 2 strings together.