Raised This Month: $ Target: $400
 0% 

Initilize copy back strings


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Mr. Zero
Veteran Member
Join Date: Jun 2009
Location: Denmark
Old 07-15-2011 , 19:13   Initilize copy back strings
Reply With Quote #1

So I have a forward that takes back a few strings.

PHP Code:
        result Plugin_Continue;
        
Call_StartForward(g_hGFwd_OnDisplay);
        
Call_PushCell(client);
        
Call_PushStringEx(namesizeof(name), SM_PARAM_STRING_UTF8SM_PARAM_COPYBACK);
        
Call_PushCell(sizeof(name));
        
Call_PushStringEx(param1sizeof(param1), SM_PARAM_STRING_UTF8SM_PARAM_COPYBACK);
        
Call_PushCell(sizeof(param1));
        
Call_PushStringEx(param2sizeof(param2), SM_PARAM_STRING_UTF8SM_PARAM_COPYBACK);
        
Call_PushCell(sizeof(param2));
        
Call_Finish(result); 
Now say another plugin changes param1 to "Hello world" and return Plugin_Changed. Then back in my call I update all the strings, unfortunately since the other two strings weren't set, they contain garbage.

So how can I set an initial value for copy back strings?

I tried strcopy into the copy back strings but that doesn't work.
Mr. Zero is offline
Wazz
SourceMod Donor
Join Date: Mar 2009
Old 07-15-2011 , 21:08   Re: Initilize copy back strings
Reply With Quote #2

I believe just doing string[0] = '\0' will be enough to initialize it. It will set the first byte to the null terminator which marks the end of the string.
Wazz is offline
bl4nk
SourceMod Developer
Join Date: Jul 2007
Old 07-16-2011 , 19:44   Re: Initilize copy back strings
Reply With Quote #3

Declare the strings with 'new' instead of 'decl' for them to be auto-initialized to 0. Or do what Wazz said.
bl4nk is offline
psychonic

BAFFLED
Join Date: May 2008
Old 07-16-2011 , 19:56   Re: Initilize copy back strings
Reply With Quote #4

You need to add SM_PARAM_STRING_COPY if you are using Call_PushStringEx and want the existing contents to be pushed through.
psychonic 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 17:03.


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