AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Using (un-identified) blocks inside functions (https://forums.alliedmods.net/showthread.php?t=27252)

commonbullet 04-18-2006 10:46

Using (un-identified) blocks inside functions
 
I didn’t see it in documentation, and I haven’t seen that in any plugin. It doesn’t show any warnings in compilation, so I suppose it works fine for cleaning variables that will not be used in the rest of function.
I know they can always be broken into two or more functions, I just wondered if it’s ok in Pawn…

Crap example:
Code:
test(){     new line[72]     {         new filepath[67], len         get_configsdir( filepath , 66 )         format(filepath , 66 , "%s/maps.ini", filepath)         read_file (filepath, 2, line, 71, len)     }     // […] }

Basic-Master 04-18-2006 14:36

maybe you should set len to something, your format call looks terrible (gasp, the entire code snippet looks awful). use something like that:
Code:
test() {   new tmp[32] // should be enough   new file[41] // the filename   new len // the length of the read line   get_configsdir(tmp, 31) // get the directory   format(file, 40, "%s/maps.ini", tmp)   read_file(file, 2, line, 31, len)   // ... }

edit: but yes, theoretically you could use blocks there..

commonbullet 04-18-2006 15:04

thanks,

well the example was terrible and wrong (len...)
but tell me is it a bad practice to use blocks like these?
- just noted I could make less memory usage in some parts of my code...

PM 04-18-2006 15:27

Quote:

Originally Posted by commonbullet
thanks,

well the example was terrible and wrong (len...)
but tell me is it a bad practice to use blocks like these?
- just noted I could make less memory usage in some parts of my code...

shouldn't be a problem to do that; except that it look pretty awful to my eyes :) although I guess it won't have a very strong effect, unless you are allocating a lot of memory on the stack.


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

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