SA-MP Forums Archive
Multiple new vs one new - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Multiple new vs one new (/showthread.php?tid=656305)



Multiple new vs one new - IdonTmiss - 12.07.2018

Umm so is this better

pawn Код:
new x;
new z;
new a;
new b;
new c;
...
or

pawn Код:
new x,
      z,
      a,
      b,
      c;



Re: Multiple new vs one new - Florin48 - 12.07.2018

I think it's the same thing, except for the second version you write less.


Re: Multiple new vs one new - IdonTmiss - 12.07.2018

Quote:
Originally Posted by ******
Посмотреть сообщение
Define "better".
Faster? Like using it in an timer or smth


Re: Multiple new vs one new - ItsRobinson - 12.07.2018

Quote:
Originally Posted by ******
Посмотреть сообщение
Then neither. And if you think that is what you need to worry about in code, you don't understand optimisations at all.
Calm down, you didn't at one point.

and no @IdonTmiss that's the exact same thing, just more neat in a way.

If you want to use less variables you can use arrays, i.e.

PHP код:
new PlayerCash[MAX_PLAYERS]; 
This would make a variable that has 999 different, "slots" lets call them.

This means that you can do something like this.

PHP код:
if(PlayerCash[0] == 0)
{
    
SendClientMessage(0, -1"Ha Ha, you're poor.");

That above would check to see what integer is stored to PlayerCash for the "slot" 0 (slot 0 being Player ID 0 on the tab list)

Very basic but you get the idea.

This also does not improve optimisation, again it's just neater.

Variables have such a tiny tiny impact on the server, you shouldn't worry about the amount of variables you're using tbh.


Re: Multiple new vs one new - Florin48 - 12.07.2018

Quote:
Originally Posted by ItsRobinson
Посмотреть сообщение
Calm down, you didn't at one point.

and no @IdonTmiss that's the exact same thing, just more neat in a way.

If you want to use less variables you can use arrays, i.e.

PHP код:
new PlayerCash[MAX_PLAYERS]; 
This would make a variable that has 999 different, "slots" lets call them.

This means that you can do something like this.

PHP код:
if(PlayerCash[0] == 0)
{
    
SendClientMessage(0, -1"Ha Ha, you're poor.");

That above would check to see what integer is stored to PlayerCash for the "slot" 0 (slot 0 being Player ID 0 on the tab list)

Very basic but you get the idea.

This also does not improve optimisation, again it's just neater.

Variables have such a tiny tiny impact on the server, you shouldn't worry about the amount of variables you're using tbh.
I read on this community at an optimization section that tin array variables are slower.
I do not know for sure whether it's true or not.


Re: Multiple new vs one new - ItsRobinson - 12.07.2018

Quote:
Originally Posted by Florin48
Посмотреть сообщение
I read on this community at an optimization section that tin array variables are slower.
I do not know for sure whether it's true or not.
Like I said, you shouldn't worry about arrays/multiple variables the impact is absolutely minuscule, also like I said, it wasn't an optimisation, just more neat than using 12 different variables.


Re: Multiple new vs one new - GangstaSunny. - 12.07.2018

I mainly use the second method. Just looks better.