SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 12/07/2018, 06:13 PM   #1
IdonTmiss
Big Clucker
 
Join Date: Dec 2016
Posts: 72
Reputation: 0
Default Multiple new vs one new

Umm so is this better

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

or

Code:
new x,
      z,
      a,
      b,
      c;
IdonTmiss is offline   Reply With Quote
Old 12/07/2018, 06:19 PM   #2
Y_Less
Spam Machine
 
Y_Less's Avatar
 
Join Date: Jun 2008
Location: 629 - git.io/Y
Posts: 14,812
Reputation: 3111
Default Re: Multiple new vs one new

Define "better".
Y_Less is offline   Reply With Quote
Old 12/07/2018, 06:24 PM   #3
Florin48
Big Clucker
 
Join Date: Nov 2015
Location: Romania
Posts: 119
Reputation: 3
Default Re: Multiple new vs one new

I think it's the same thing, except for the second version you write less.
Florin48 is offline   Reply With Quote
Old 12/07/2018, 06:30 PM   #4
IdonTmiss
Big Clucker
 
Join Date: Dec 2016
Posts: 72
Reputation: 0
Default Re: Multiple new vs one new

Quote:
Originally Posted by Y_Less View Post
Define "better".
Faster? Like using it in an timer or smth
IdonTmiss is offline   Reply With Quote
Old 12/07/2018, 06:31 PM   #5
Y_Less
Spam Machine
 
Y_Less's Avatar
 
Join Date: Jun 2008
Location: 629 - git.io/Y
Posts: 14,812
Reputation: 3111
Default 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.
Y_Less is offline   Reply With Quote
Old 12/07/2018, 06:42 PM   #6
ItsRobinson
Big Clucker
 
ItsRobinson's Avatar
 
Join Date: Sep 2017
Posts: 71
Reputation: 9
Default Re: Multiple new vs one new

Quote:
Originally Posted by Y_Less View Post
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.
__________________


ItsRobinson is offline   Reply With Quote
Old 12/07/2018, 06:45 PM   #7
Florin48
Big Clucker
 
Join Date: Nov 2015
Location: Romania
Posts: 119
Reputation: 3
Default Re: Multiple new vs one new

Quote:
Originally Posted by ItsRobinson View Post
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.
Florin48 is offline   Reply With Quote
Old 12/07/2018, 06:57 PM   #8
ItsRobinson
Big Clucker
 
ItsRobinson's Avatar
 
Join Date: Sep 2017
Posts: 71
Reputation: 9
Default Re: Multiple new vs one new

Quote:
Originally Posted by Florin48 View Post
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.
__________________


ItsRobinson is offline   Reply With Quote
Old 12/07/2018, 07:02 PM   #9
Y_Less
Spam Machine
 
Y_Less's Avatar
 
Join Date: Jun 2008
Location: 629 - git.io/Y
Posts: 14,812
Reputation: 3111
Default Re: Multiple new vs one new

Quote:
Originally Posted by ItsRobinson View Post
Calm down, you didn't at one point.
No, that's why we tell people.
Y_Less is offline   Reply With Quote
Old 12/07/2018, 10:16 PM   #10
GangstaSunny.
Huge Clucker
 
GangstaSunny.'s Avatar
 
Join Date: Apr 2010
Location: Hamburg - Germany
Posts: 205
Reputation: 23
Default Re: Multiple new vs one new

I mainly use the second method. Just looks better.
__________________
Visit my Website
https://gangstasunny.de
GangstaSunny. is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to multiple a value.. Azzeto Scripting Help 3 07/02/2012 01:22 AM
How to get multiple ID's? Super_Panda Scripting Help 10 16/12/2011 01:53 AM
Multiple uses of /set cloudysky Help Archive 4 12/07/2011 04:33 PM
multiple ifs shadowdog Help Archive 9 18/01/2011 01:25 PM
multiple servers with multiple ips on linux yakuzza Server Support 2 09/10/2010 07:08 PM


All times are GMT. The time now is 06:44 PM.


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