AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Change String value on a native callback? (https://forums.alliedmods.net/showthread.php?t=204573)

Starbish 01-01-2013 00:15

Change String value on a native callback?
 
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.

berni 01-01-2013 01:17

Re: Change String value on a native callback?
 
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.

Starbish 01-01-2013 01:38

Re: Change String value on a native callback?
 
Quote:

Originally Posted by berni (Post 1864604)
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!!!!

Powerlord 01-02-2013 14:27

Re: Change String value on a native callback?
 
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).

berni 01-02-2013 23:25

Re: Change String value on a native callback?
 
Arrays can always be overwritten I think.

Powerlord 01-03-2013 09:35

Re: Change String value on a native callback?
 
Quote:

Originally Posted by berni (Post 1865917)
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.

asherkin 01-03-2013 09:41

Re: Change String value on a native callback?
 
Quote:

Originally Posted by Powerlord (Post 1866129)
implies that's wrong

It is.

kazya3 04-10-2024 02:56

Re: Change String value on a native callback?
 
Quote:

Originally Posted by berni (Post 1864604)
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!:bacon!:


All times are GMT -4. The time now is 13:10.

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