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

Is this a StrCat bug? (solved)


Post New Thread Reply   
 
Thread Tools Display Modes
step
Senior Member
Join Date: May 2010
Old 07-16-2010 , 23:23   Re: Is this a StrCat bug?
Reply With Quote #11

Ok, now it's fixed :)
Thanks a lot for the tips!

PHP Code:
CreateFilePath(String:buffer[], maxlength)
{
    static 
String:game[32];
    static 
String:version[32];
    
decl String:date[32];
    
decl String:temp[128];
    
    
// game name
    
if (strlen(game) == 0)
    {
        
GetGameFolderName(gamesizeof(game));
    }
    
    
// game version
    
if (strlen(version) == 0)
    {
        new 
Handle:file OpenFile("steam.inf""r");
        
ReadFileLine(filetempsizeof(temp));
        
CloseHandle(file);
        
TrimString(temp);
        new 
int;
        
int FindCharInString(temp'='false);
        
StrCat(versionsizeof(version), temp[int]);
        
ReplaceString(versionsizeof(version), "=""v");
        
ReplaceString(versionsizeof(version), ".""");
    }
    
    
// date & time
    
FormatTime(datesizeof(date), NULL_STRING);
    
ReplaceString(datesizeof(date), "/""_");
    
ReplaceString(datesizeof(date), " - ""_");
    
ReplaceString(datesizeof(date), ":""_");
    
ReplaceString(datesizeof(date), " ""_");
    
    
// path
    
BuildPath(Path_SMtempsizeof(temp), "logs\\%s_%s_%s.txt"gameversiondate);
    
    
// return
    
strcopy(buffermaxlengthtemp);


Last edited by step; 07-16-2010 at 23:28.
step is offline
Greyscale
SourceMod Plugin Approver
Join Date: Dec 2007
Location: strYoMommasHouse[you];
Old 07-16-2010 , 23:30   Re: Is this a StrCat bug?
Reply With Quote #12

I'm not sure if static empties the string. Does anyone know? You should leave the = ""; to be safe.
__________________
Greyscale is offline
step
Senior Member
Join Date: May 2010
Old 07-16-2010 , 23:44   Re: Is this a StrCat bug?
Reply With Quote #13

Quote:
Originally Posted by Greyscale View Post
I'm not sure if static empties the string. Does anyone know? You should leave the = ""; to be safe.
I tested several times with PrintConsole's inside the if's and it's always 0.
It acts like decl, but it only does it once, which was the problem with decl in the first place.
So, I guess that I could always use static for strings, when inside loops, instead of decl, since I don't assign any values in the declarations.

Last edited by step; 07-16-2010 at 23:53.
step is offline
Seta00
The Seta00 user has crashed.
Join Date: Jan 2010
Location: Berlin
Old 07-17-2010 , 15:18   Re: Is this a StrCat bug?
Reply With Quote #14

Quote:
Originally Posted by Greyscale View Post
I'm not sure if static empties the string. Does anyone know? You should leave the = ""; to be safe.
static only means it will allocate (exactly as 'new' does) the variable only once. If you assign a value on declaration the compiler will give you an error.
By the way, you should know this as a plugin approver.

Last edited by Seta00; 07-17-2010 at 15:21.
Seta00 is offline
p3tsin
Senior Member
Join Date: Sep 2005
Location: Finland
Old 07-17-2010 , 16:02   Re: Is this a StrCat bug?
Reply With Quote #15

Quote:
Originally Posted by Seta00 View Post
If you assign a value on declaration the compiler will give you an error.
No it won't. It will initialize the var with that value, as long as its a constant.
You should know this as a veteran member.
__________________
plop
p3tsin is offline
Greyscale
SourceMod Plugin Approver
Join Date: Dec 2007
Location: strYoMommasHouse[you];
Old 07-17-2010 , 16:39   Re: Is this a StrCat bug?
Reply With Quote #16

From SourceMod entity_prop_stocks.inc

Code:
/**
 * Sets an entity's movetype.
 *
 * @param entity	Entity index.
 * @param mt		Movetype, see enum above.
 * @noreturn
 * @error			Invalid entity index, or lack of mod compliance.
 */
stock SetEntityMoveType(entity, MoveType:mt)
{
	static bool:gotconfig = false;
	static String:datamap[32];
	
	if (!gotconfig)
	{
		new Handle:gc = LoadGameConfigFile("core.games");
		new bool:exists = GameConfGetKeyValue(gc, "m_MoveType", datamap, sizeof(datamap));
		CloseHandle(gc);
		
		if (!exists)
		{
			strcopy(datamap, sizeof(datamap), "m_MoveType");
		}
		
		gotconfig = true;
	}
	
	SetEntProp(entity, Prop_Data, datamap, mt);
}

And by the way 'decl' allocates, 'new' allocates AND initializes to a value. So I think you mean static is like 'decl' but allocates only once.
__________________

Last edited by Greyscale; 07-17-2010 at 16:41.
Greyscale is offline
Seta00
The Seta00 user has crashed.
Join Date: Jan 2010
Location: Berlin
Old 07-17-2010 , 18:27   Re: Is this a StrCat bug?
Reply With Quote #17

Quote:
Originally Posted by p3tsin View Post
as long as its a constant.
bah, details

Quote:
Originally Posted by Greyscale View Post
And by the way 'decl' allocates, 'new' allocates AND initializes to a value. So I think you mean static is like 'decl' but allocates only once.
No, I meant static initializes to zero.
Seta00 is offline
rhelgeby
Veteran Member
Join Date: Oct 2008
Location: 0x4E6F72776179
Old 07-17-2010 , 23:29   Re: Is this a StrCat bug? (solved)
Reply With Quote #18

About those strings, just do this:

PHP Code:
decl String:myString[SOME_HIGH_VALUE];
myString[0] = 0
That will do a quick initialization. On long strings this will save some time. Although, if you're going to access a random index in the string for the first time, you have to use new instead of decl.
__________________
Richard Helgeby

Zombie:Reloaded | PawnUnit | Object Library
(Please don't send private messages for support, they will be ignored. Use the forum.)
rhelgeby is offline
Send a message via MSN to rhelgeby
step
Senior Member
Join Date: May 2010
Old 07-18-2010 , 10:40   Re: Is this a StrCat bug? (solved)
Reply With Quote #19

Quote:
Originally Posted by rhelgeby View Post
About those strings, just do this:

PHP Code:
decl String:myString[SOME_HIGH_VALUE];
myString[0] = 0
That will do a quick initialization. On long strings this will save some time. Although, if you're going to access a random index in the string for the first time, you have to use new instead of decl.
That is the same as

decl String:myString[SOME_HIGH_VALUE] = "";

right?
step 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 10:38.


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