SA-MP Forums

SA-MP Forums (https://forum.sa-mp.com/index.php)
-   Scripting Help (https://forum.sa-mp.com/forumdisplay.php?f=12)
-   -   Multiple new vs one new (https://forum.sa-mp.com/showthread.php?t=656305)

IdonTmiss 12/07/2018 06:13 PM

Multiple new vs one new
 
Umm so is this better

pawn Code:
new x;
new z;
new a;
new b;
new c;
...

or

pawn Code:
new x,
      z,
      a,
      b,
      c;

Y_Less 12/07/2018 06:19 PM

Re: Multiple new vs one new
 
Define "better".

Florin48 12/07/2018 06:24 PM

Re: Multiple new vs one new
 
I think it's the same thing, except for the second version you write less.

IdonTmiss 12/07/2018 06:30 PM

Re: Multiple new vs one new
 
Quote:

Originally Posted by Y_Less (Post 4036213)
Define "better".

Faster? Like using it in an timer or smth

Y_Less 12/07/2018 06:31 PM

Re: Multiple new vs one new
 
Then neither. And if you think that is what you need to worry about in code, you don't understand optimisations at all.

ItsRobinson 12/07/2018 06:42 PM

Re: Multiple new vs one new
 
Quote:

Originally Posted by Y_Less (Post 4036219)
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 Code:

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 Code:

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.

Florin48 12/07/2018 06:45 PM

Re: Multiple new vs one new
 
Quote:

Originally Posted by ItsRobinson (Post 4036229)
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 Code:

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 Code:

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.

ItsRobinson 12/07/2018 06:57 PM

Re: Multiple new vs one new
 
Quote:

Originally Posted by Florin48 (Post 4036231)
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.

Y_Less 12/07/2018 07:02 PM

Re: Multiple new vs one new
 
Quote:

Originally Posted by ItsRobinson (Post 4036229)
Calm down, you didn't at one point.

No, that's why we tell people.

GangstaSunny. 12/07/2018 10:16 PM

Re: Multiple new vs one new
 
I mainly use the second method. Just looks better.


All times are GMT. The time now is 08:24 PM.

Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.