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

Change String value on a native callback?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Starbish
AlliedModders Donor
Join Date: Oct 2011
Location: South Korea
Old 01-01-2013 , 00:15   Change String value on a native callback?
Reply With Quote #1

I'd like to change String value which is got from Native Parameters.

Example)

native Example(client, String:strExample[], iMaxLength);

new String:strExample[32];
Example(client, strExample, sizeof(strExample));



Like this, I want to make it if i call Example(), second params of Example() will store something not NULL_STRING.

like, GetClientName().


and i found this; FormatNativeString() but i couldn't know how to use this.

I tried to find the ways in many websites(such as Searching google, SourceMod-Wiki) but there were the ways just for VFormat in Native.
__________________
Starbish is offline
berni
SourceMod Plugin Approver
Join Date: May 2007
Location: Austria
Old 01-01-2013 , 01:17   Re: Change String value on a native callback?
Reply With Quote #2

Hello Starbish,

you basically have to call SetNativeString() after you set the string to write the string buffer back for the caller.

There is an example in the wiki:
http://wiki.alliedmods.net/Creating_...pting)#Strings

The function FormatNativeString is a formatter function with printf syntax, that parses %s, %d formatters from variable arguments, but to change the string buffer you basically don't need it, except you want to have variable argument formatting support.
It's described in the API Doc.
__________________
Why reinvent the wheel ? Download smlib with over 350 useful functions.

When people ask me "Plz" just because it's shorter than "Please" I feel perfectly justified to answer "No" because it's shorter than "Yes"
powered by Core i7 3770k | 32GB DDR3 1886Mhz | 2x Vertex4 SSD Raid0
berni is offline
Starbish
AlliedModders Donor
Join Date: Oct 2011
Location: South Korea
Old 01-01-2013 , 01:38   Re: Change String value on a native callback?
Reply With Quote #3

Quote:
Originally Posted by berni View Post
Hello Starbish,

you basically have to call SetNativeString() after you set the string to write the string buffer back for the caller.

There is an example in the wiki:
http://wiki.alliedmods.net/Creating_...pting)#Strings

The function FormatNativeString is a formatter function with printf syntax, that parses %s, %d formatters from variable arguments, but to change the string buffer you basically don't need it, except you want to have variable argument formatting support.
It's described in the API Doc.
Thank you Berni!

You answered exactly what i wanted !

I really appreciated with your answer and understanding my Bad English = )

REALLY THANK YOU!!!!
__________________
Starbish is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 01-02-2013 , 14:27   Re: Change String value on a native callback?
Reply With Quote #4

The native has to expect that the string can be modified (i.e. Call_PushStringEx is declared with SM_PARAM_COPYBACK in its fourth argument).
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
berni
SourceMod Plugin Approver
Join Date: May 2007
Location: Austria
Old 01-02-2013 , 23:25   Re: Change String value on a native callback?
Reply With Quote #5

Arrays can always be overwritten I think.
__________________
Why reinvent the wheel ? Download smlib with over 350 useful functions.

When people ask me "Plz" just because it's shorter than "Please" I feel perfectly justified to answer "No" because it's shorter than "Yes"
powered by Core i7 3770k | 32GB DDR3 1886Mhz | 2x Vertex4 SSD Raid0
berni is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 01-03-2013 , 09:35   Re: Change String value on a native callback?
Reply With Quote #6

Quote:
Originally Posted by berni View Post
Arrays can always be overwritten I think.
The documentation for the third argument to Call_PushArrayEx ("Whether or not changes should be copied back to the input array") implies that's wrong, but I haven't checked the C++ side to make sure.

The same argument is the fourth argument to Call_PushStringEx.
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 01-03-2013 at 09:40.
Powerlord is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 01-03-2013 , 09:41   Re: Change String value on a native callback?
Reply With Quote #7

Quote:
Originally Posted by Powerlord View Post
implies that's wrong
It is.
__________________
asherkin is offline
kazya3
Member
Join Date: Aug 2019
Location: CN
Old 04-10-2024 , 02:56   Re: Change String value on a native callback?
Reply With Quote #8

Quote:
Originally Posted by berni View Post
Hello Starbish,
you basically have to call SetNativeString() after you set the string to write the string buffer back for the caller.
I was suffering from the problems for some hours. You are my hero!
__________________
kazya3 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:04.


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