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

When do u use constants?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Callmenoob
New Member
Join Date: Nov 2015
Old 12-09-2017 , 09:11   When do u use constants?
Reply With Quote #1

Hi I have a very simple question, which u may even consider stupid.
When do u use constans? For example in functions or while defining something.
What do they exactly do?
It may sound like a newbie question but i more or less writed some plugins for sourcemod since winter 2016. And i never used constants. I created many plugins for my server like my own jailbreak game/warden system, vip plugins, slots etc. Or edited many plugins, but i still don't get what constant does and what can u gain from using that.
Callmenoob is offline
91346706501435897134
Member
Join Date: Oct 2017
Old 12-09-2017 , 12:33   Re: When do u use constants?
Reply With Quote #2

Quote:
Originally Posted by Callmenoob View Post
Hi I have a very simple question, which u may even consider stupid.
When do u use constans? For example in functions or while defining something.
What do they exactly do?
It may sound like a newbie question but i more or less writed some plugins for sourcemod since winter 2016. And i never used constants. I created many plugins for my server like my own jailbreak game/warden system, vip plugins, slots etc. Or edited many plugins, but i still don't get what constant does and what can u gain from using that.
constant variables are variables that never change.
91346706501435897134 is offline
hmmmmm
Great Tester of Whatever
Join Date: Mar 2017
Location: ...
Old 12-09-2017 , 14:34   Re: When do u use constants?
Reply With Quote #3

If you mean the 'const' keyword, it simply makes it so you can't modify the value of the variable after it is initialized. Very useful for minimizing human error when you have a variable that's never meant to change, the compiler will throw an error and let you know immediately rather than having plugin failing later and making you have to go through the trouble of debugging it. It's also used very often for forwards to make sure that values of arrays/strings, which are always passed in by reference, aren't changed by any plugins when they're not meant to.

Unfortunately, using const outside of function parameters doesn't work anymore in new syntax.

Last edited by hmmmmm; 12-09-2017 at 14:35.
hmmmmm is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 12-10-2017 , 04:36   Re: When do u use constants?
Reply With Quote #4

Quote:
Originally Posted by hmmmmm View Post
Unfortunately, using const outside of function parameters doesn't work anymore in new syntax.
It didn’t work before either, it was just silently dropped.
__________________
asherkin 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 23:11.


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