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

Setting invisibility amount [help]


Post New Thread Reply   
 
Thread Tools Display Modes
xines
Veteran Member
Join Date: Aug 2013
Location: Denmark
Old 06-28-2015 , 13:04   Re: Setting invisibility amount [help]
Reply With Quote #11

Okay, i'll just stick to "new" then, still not sure about the sizes tho, i'm a read about it later, but thanks everyone!
xines is offline
headline
SourceMod Moderator
Join Date: Mar 2015
Old 06-28-2015 , 13:10   Re: Setting invisibility amount [help]
Reply With Quote #12

Quote:
Originally Posted by ThatOneGuy View Post
lol...headline, you do the same thing in your beacon plugin. The cvar you just added is g_bSomething [i forget the name], but it isnt a boolean,...tis an integer...not worth changing as you didnt actually declare it as a boolean, nor do you handle it as one, so it works fine. But i thought that it was funny you commenting to that.

Anyway, he changed the word new to decl to optimize your plugin a little. new sets aside the full size for the string (32), where decl only makes the variable able to go that big, but only uses as much memory as is actually used to format your string. There's no need to move them to separate lines though.


LOL Oops.
headline is offline
ThatOneGuy
Veteran Member
Join Date: Jul 2012
Location: Oregon, USA
Old 06-29-2015 , 02:13   Re: Setting invisibility amount [help]
Reply With Quote #13

Quote:
Originally Posted by necavi View Post
Always use new, decl isn't even available in the new syntax. Sizes can be a bit harder, you have to think about how many characters you'll really need (and then generally add a few more), there are some defines to help you, such as PLATFORM_MAX_PATH for filepaths and a few others.
I dont know about new syntax not using decl, nor have I ever even read that to be the case. Seems silly to get rid of something having to do with optimization that could make/break some plugins executing certain code in OnGameFrame (or other frequent events). For many things, the difference is insignificant, but functions that repeat multiple times/second (OnGameFrame, OnPlayerRunCmd, etc) and have a lot of processing, decl can be very important to use for strings and arrays. The only downside is when people misuse it in the sense of trying to read the variable before something is saved to it, which will spit out garbage or whatever was last saved in that piece of memory (and could even crash a server). But dont remove optimization options just because some people might ignorantly skip proper checks and code planning.

From the developer log (http://www.sourcemod.net/devlog/?p=85):
Spoiler


While bail has later himself said that it is a messy operation, it is mainly due to people trying to read a value before it is set properly.

Other documentation:
https://wiki.alliedmods.net/Introduc...ourcePawn#decl
https://wiki.alliedmods.net/Optimizi...n_Local_Arrays
__________________
ThatOneGuy is offline
Kolapsicle
Senior Member
Join Date: Oct 2014
Old 06-29-2015 , 06:00   Re: Setting invisibility amount [help]
Reply With Quote #14

Quote:
Originally Posted by xines View Post
Getting quite confused about the "new, decl" thing, whenever to use new or decl, and about what sizes i need to use like [32] [128] and so on
It's probably easier to understand if I give you an example.

PHP Code:
new String:mystring[32];
Format(mystringsizeof(mystring), "more than 32 characters will be truncated");
PrintToChatAll("[SM] Print: %s"mystring); 


The chat output would be "[SM] Print: more than 32 characters will be". This is because the array is only 32 bytes large which means it can only hold 32 characters. In my example mystring would need to be 42 bytes large in order to hold the full format string.

Last edited by Kolapsicle; 06-29-2015 at 06:03.
Kolapsicle is offline
xines
Veteran Member
Join Date: Aug 2013
Location: Denmark
Old 06-29-2015 , 08:54   Re: Setting invisibility amount [help]
Reply With Quote #15

Quote:
Originally Posted by Kolapsicle View Post
It's probably easier to understand if I give you an example.

PHP Code:
new String:mystring[32];
Format(mystringsizeof(mystring), "more than 32 characters will be truncated");
PrintToChatAll("[SM] Print: %s"mystring); 


The chat output would be "[SM] Print: more than 32 characters will be". This is because the array is only 32 bytes large which means it can only hold 32 characters. In my example mystring would need to be 42 bytes large in order to hold the full format string.

Ahh okay, that makes sense now thanks man!
xines 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 14:22.


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