Raised This Month: $ Target: $400
 0% 

Setting invisibility amount [help]


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Kolapsicle
Senior Member
Join Date: Oct 2014
Old 06-29-2015 , 06:00   Re: Setting invisibility amount [help]
Reply With Quote #1

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 #2

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
necavi
Veteran Member
Join Date: Sep 2010
Old 06-28-2015 , 12:45   Re: Setting invisibility amount [help]
Reply With Quote #3

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.
necavi 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 #4

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
xines
Veteran Member
Join Date: Aug 2013
Location: Denmark
Old 06-28-2015 , 13:04   Re: Setting invisibility amount [help]
Reply With Quote #5

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
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 13:28.


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