Raised This Month: $32 Target: $400
 8% 

[HElp] variable "const"


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Dr Zayd
Senior Member
Join Date: Jun 2014
Location: forums.alliedmods.net
Old 08-17-2016 , 22:49   [HElp] variable "const"
Reply With Quote #1

Is there a way to make this const changeable ?
PHP Code:
 new const zclass_info[] =  { "Infos about Zm" 
I mean as an exemple :

PHP Code:
if is user VIP/Admin
new const zclass_info[] =  { "Infos about zm" }
else
new const 
zclass_info[] =  { "VIP/Admin Only" 
__________________
Invisible System | 100%
ـــــــــــــــــــــــــــــ
Anti setinfo check | Ez Plugin and lite
ـــــــــــــــــــــــــــــ
[ZP] Free VIP Menu | Free VIP menu | ZP-Mod |

Last edited by Dr Zayd; 08-19-2016 at 20:53. Reason: Title change
Dr Zayd is offline
Dr Zayd
Senior Member
Join Date: Jun 2014
Location: forums.alliedmods.net
Old 08-19-2016 , 20:54   Re: [HElp] variable "const"
Reply With Quote #2

UP ..
__________________
Invisible System | 100%
ـــــــــــــــــــــــــــــ
Anti setinfo check | Ez Plugin and lite
ـــــــــــــــــــــــــــــ
[ZP] Free VIP Menu | Free VIP menu | ZP-Mod |
Dr Zayd is offline
Old 08-19-2016, 21:05
wickedd
This message has been deleted by wickedd. Reason: NVM
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 08-19-2016 , 21:14   Re: [HElp] variable "const"
Reply With Quote #3

const is short for constant . . . By definition, the variable is no longer constant if it changes.

Also, you shouldn't create variables inside an if statement that are intended to be used outside the if statement.

So, you should declare the string as a normal variable indexed with the maximum number of characters that you expect might be used in there. Then, use copy() to populate the string variable:

Code:
copy(zclass_info, charsmax(zclass_info), "string goes here")
__________________

Last edited by fysiks; 08-19-2016 at 21:15.
fysiks is offline
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 08-20-2016 , 17:44   Re: [HElp] variable "const"
Reply With Quote #4

Just don't make it a constant variable and change it where you need it to change?

declaring it is simple by just typing "new variable[] = "new var"", also we're actually talking about arrays here..

If you wanna change the value of it, you can just use this "variable = "String""
__________________
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
Craxor
Veteran Member
Join Date: Jan 2016
Location: Romania
Old 08-20-2016 , 21:13   Re: [HElp] variable "const"
Reply With Quote #5

If you want to change strings/text in your plugin you should do it with cvars.

If not use formatex or copy.
Craxor is offline
Send a message via ICQ to Craxor
Old 08-20-2016, 21:39
addons_zz
This message has been deleted by addons_zz. Reason: wrong code
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 08-21-2016 , 00:46   Re: [HElp] variable "const"
Reply With Quote #6

Quote:
Originally Posted by Napoleon_be View Post
If you wanna change the value of it, you can just use this "variable = "String""
No! Do not assign a string to an array variable. You should always use copy, format, formatex or other string formatting functions. If you assign it directly, it is very easy to cause an overflow.
__________________

Last edited by fysiks; 08-21-2016 at 00:46.
fysiks is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 08-21-2016 , 03:32   Re: [HElp] variable "const"
Reply With Quote #7

Actually I am pretty certain that it's perfecrly safe. The compiler should issue an error if you try to assign an array that's bigger than destination array.
klippy is offline
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 08-21-2016 , 05:56   Re: [HElp] variable "const"
Reply With Quote #8

Quote:
Originally Posted by fysiks View Post
No! Do not assign a string to an array variable. You should always use copy, format, formatex or other string formatting functions. If you assign it directly, it is very easy to cause an overflow.
I don't think this should be a problem since you don't tag the variable? I'm not sure though, correct me if i'm wrong.
__________________
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
Dr Zayd
Senior Member
Join Date: Jun 2014
Location: forums.alliedmods.net
Old 08-21-2016 , 20:56   Re: [HElp] variable "const"
Reply With Quote #9

Thanks all that was helpful.
__________________
Invisible System | 100%
ـــــــــــــــــــــــــــــ
Anti setinfo check | Ez Plugin and lite
ـــــــــــــــــــــــــــــ
[ZP] Free VIP Menu | Free VIP menu | ZP-Mod |
Dr Zayd is offline
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

Forum Jump


All times are GMT -4. The time now is 19:14.


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