Raised This Month: $51 Target: $400
 12% 

What is the difference in the way these variables are declared?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Leech_v2
Senior Member
Join Date: Mar 2011
Location: Chinese GuangDong
Old 10-06-2023 , 16:10   What is the difference in the way these variables are declared?
Reply With Quote #1

What is the difference between adding 'new' and removing 'new'?

What I want to know is the purpose of using 'new' in combination with other specifier.
As far as I know, the feature of 'new' is that it allows declared variables to use runtime expressions as initialization expressions. However, runtime expressions cannot be used outside of a function, so I am wondering why it can be combined with other specifier?

Code:
new stock gVar;
stock gVar;

new static gVar;
static gVar;

new public gVar;
public gVar;

new static stock gVar;
static stock gVar;

Last edited by Leech_v2; 10-07-2023 at 01:34. Reason: Add more explanation
Leech_v2 is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 10-06-2023 , 21:44   Re: What is the difference in the way these variables are declared?
Reply With Quote #2

See page 61 (PDF page 65)

https://raw.githubusercontent.com/co.../pawn-lang.pdf
__________________
Bugsy is offline
Leech_v2
Senior Member
Join Date: Mar 2011
Location: Chinese GuangDong
Old 10-07-2023 , 01:16   Re: What is the difference in the way these variables are declared?
Reply With Quote #3

Quote:
Originally Posted by Bugsy View Post
? The file you sent did not explain my problem.
What I want to know is the purpose of using 'new' in combination with other specifier.
As far as I know, the feature of 'new' is that it allows declared variables to use runtime expressions as initialization expressions. However, runtime expressions cannot be used outside of a function, so I am wondering why it can be combined with other specifier?

Last edited by Leech_v2; 10-07-2023 at 01:31.
Leech_v2 is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 10-07-2023 , 02:42   Re: What is the difference in the way these variables are declared?
Reply With Quote #4

"new" just creates a new variable of local scope. If it's used on the top-level, it's effectively a global variable with respect to the plugin's own code. When declared in this scope, there is no runtime execution happening so only constant expressions are allowed. When you create a variable in a local scope that is processed at runtime (like inside of a function) then you can initialize it with any normal code.

"new", "static", and "public" are mutually exclusive expressions so I'm not sure why you have any combination of those. References:

Quote:
Originally Posted by Pawn Language Guide
To declare a global variable as static, replace the keyword new by static.
Quote:
Originally Posted by Pawn Language Guide
Global “simple” variables (no arrays) may be declared “public”
in two ways:
⋄ declare the variable using the keyword public instead of new;
...
__________________

Last edited by fysiks; 10-07-2023 at 02:45.
fysiks is offline
Leech_v2
Senior Member
Join Date: Mar 2011
Location: Chinese GuangDong
Old 10-07-2023 , 04:03   Re: What is the difference in the way these variables are declared?
Reply With Quote #5

Quote:
Originally Posted by fysiks View Post
"new" just creates a new variable of local scope. If it's used on the top-level, it's effectively a global variable with respect to the plugin's own code. When declared in this scope, there is no runtime execution happening so only constant expressions are allowed. When you create a variable in a local scope that is processed at runtime (like inside of a function) then you can initialize it with any normal code.

"new", "static", and "public" are mutually exclusive expressions so I'm not sure why you have any combination of those. References:
Because in actual testing, 'new' can be combined with 'public', 'static', and 'stock'.
That's why I have questions
Leech_v2 is offline
Jhob94
AMX Mod X Donor
Join Date: Jul 2012
Old 10-07-2023 , 06:01   Re: What is the difference in the way these variables are declared?
Reply With Quote #6

Pawn is a dead language for several years and it happens because this is not the most reliable language.
The deeper you look the more senseless stuff you'll find.
AMXX, SourceMod and SA:MP are the only ones using it. We still use it because it's a choice from many many years when Pawn could still improve and now it is kinda too late to change because of the massive work that the community has been doing all those years.
__________________
Jhob94 is offline
thEsp
BANNED
Join Date: Aug 2017
Old 10-07-2023 , 06:26   Re: What is the difference in the way these variables are declared?
Reply With Quote #7

Quote:
Originally Posted by Leech_v2 View Post
Because in actual testing, 'new' can be combined with 'public', 'static', and 'stock'.
That's why I have questions
static allocates a variable but doesn't guarantee to free it in the end of the body. public does what it says - exposes the variable to the virtual machine. stock is nothing special it just tells the compiler to discard the following identifier if it's never used.

Quote:
Pawn is a dead language for several years...
Since you're that smart guy why don't you go ahead and create a new magnificent language, compiler and runtime?
thEsp is offline
Jhob94
AMX Mod X Donor
Join Date: Jul 2012
Old 10-07-2023 , 07:06   Re: What is the difference in the way these variables are declared?
Reply With Quote #8

I just stated a fact. I like pawn but facts are facts.
He isn’t asking what public, static and stock does he is asking why we can combine them.
__________________
Jhob94 is offline
thEsp
BANNED
Join Date: Aug 2017
Old 10-07-2023 , 14:41   Re: What is the difference in the way these variables are declared?
Reply With Quote #9

Quote:
why we can combine them.
Semantics.

Quote:
I just stated a fact. I like pawn but facts are facts.
Then don't complain about some useless thing you regularly use, weirdo.
thEsp is offline
Jhob94
AMX Mod X Donor
Join Date: Jul 2012
Old 10-07-2023 , 15:03   Re: What is the difference in the way these variables are declared?
Reply With Quote #10

Where did i say it’s useless? You are talking non-sense
__________________
Jhob94 is offline
Reply



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

Forum Jump


All times are GMT -4. The time now is 09:04.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode