For direct access use https://forums.oldunreal.com
It's been quite a while since oldunreal had an overhaul, but we are moving to another server which require some updates and changes. The biggest change is the migration of our old reliable YaBB forum to phpBB. This system expects you to login with your username and old password known from YaBB.
If you experience any problems there is also the usual "password forgotten" function. Don't forget to clear your browser cache!
If you have any further concerns feel free to contact me: Smirftsch@oldunreal.com

ExecFunctionStr

The section related to UnrealScript and modding. This board is for coders to discuss and exchange experiences or ask questions.
Post Reply
User avatar
Bleeder91[NL]
OldUnreal Member
Posts: 1062
Joined: Sun Oct 04, 2009 7:22 pm

ExecFunctionStr

Post by Bleeder91[NL] »

Code: Select all

// Call a function by name and string parameters.
// Parms are separated by '\' character, diferent parms can also be enclosed by citate char, as ex:
// ExecFunctionStr('TestCode',"45\\\"Hello world\");
// Which will compile as: 45\"Hello world"
// Returns True if function was found and executed.
// @ ReturnValue = filled with the return value if exists.

native(390) final function bool ExecFunctionStr( name FuncName, string Parms, optional out string ReturnVal );
I don't get how this works. I'm using it like this:

Code: Select all

// The Data Actor.
Function HandleData(name Action, string PActorName, string PPlayerName)
{
      log(PActorName @PPlayerName);
}

// The Calling Actor.
Data.ExecFunctionStr('HandleData',"Load//" $string(PlayerActor.Name) $"//" $PlayerName);
It'll return "" for me in the log. The description for it is incorrect or something. I am forced to use 2x "\" because else it'll give an unfinished string error, which is 'obvious', that I get. But how does it know what param I'm giving in my example? And in the example the \ is inside the "" so shouldn't it be returning "hello world\"? I'm confuzzled. :-/
Image
User avatar
yrex .
OldUnreal Member
Posts: 275
Joined: Wed May 06, 2015 6:46 am
Contact:

Re: ExecFunctionStr

Post by yrex . »

The description seems to be missing the last ", otherwise it would probably make syntax error.

The \\ seems to evaluate to \, and \" evaluates to the " character. (All of that defines the value of the string, it's not related to the "outer" quotations.)

So then in your case it should be:

Code: Select all

Data.ExecFunctionStr('HandleData',"Load\\\"" $ string(PlayerActor.Name) $ "\"\\\"" $ PlayerName $ "\""); 
Which would evaluate like:

"Load\\\"" -> Load\"
"\"\\\"" -> "\"
"\"" -> "

E.g. Load\"actor name here"\"player name here"

I wonder what if somebody actually wanted to pass the " or \ to a parameter here...
Last edited by yrex . on Sun Nov 05, 2017 5:20 pm, edited 1 time in total.
My work | contact: ampoyrex at wp dot pl
User avatar
Masterkent
OldUnreal Member
Posts: 1469
Joined: Fri Apr 05, 2013 12:41 pm

Re: ExecFunctionStr

Post by Masterkent »

I can only tell a few facts based on my own observations (no idea how ExecFunctionStr is implemented, because I don't have its source code; maybe if you pay Smirftsch $1000, he will tell you how this function really works).

Firstly, the real argument separator is comma, not backslash. I couldn't notice any special handling of backslashes by ExecFunctionStr - they seem to be treated as regular characters. Of course, within string literals (which are transformed into strings by the UScript compiler), backslashes have special meaning (they form escape sequences), but this feature is not related to ExecFunctionStr.

For example, if we have

Code: Select all

function SomeProc(string S, int I, float F, Object Obj)
{
      BroadcastMessage(S $ "," @ I $ "," @ F $ "," @ Obj);
}
then

Code: Select all

ExecFunctionStr('SomeProc', "One\\Two,123,3.14," $ Level);
has the same effect as

Code: Select all

SomeProc("One\\Two", 123, 3.14, FindObject(class'Object', string(Level)));
Secondly, enclosing arguments by " does not work as described in the comments. It simply messes up argument passing and does not do anything useful. So, as long as you don't need to pass strings containing commas or strings starting with ", ExecFunctionStr may work well for you (if you don't trigger any undocumented "feature" of this function somehow).

Native functions such as Destroy and SetTimer cannot be called via ExecFunctionStr (even though ExecFunctionStr reports successful execution by returning true).
Last edited by Masterkent on Mon Nov 06, 2017 10:49 am, edited 1 time in total.
User avatar
Bleeder91[NL]
OldUnreal Member
Posts: 1062
Joined: Sun Oct 04, 2009 7:22 pm

Re: ExecFunctionStr

Post by Bleeder91[NL] »

Thanks for the responses! Indeed a comma instead of a backslash does the job. For some reason this also sounds more logical since that's actually used to set params in a normal function call, oh well.
I'm using it together with dynamicloadobject to call actors that I don't want referenced i.e. clients don't have to download it. So this function, albeit hard to understand without the proper knowledge, does this just right.
Last edited by Bleeder91[NL] on Tue Nov 07, 2017 11:52 am, edited 1 time in total.
Image
Post Reply

Return to “UScript Board”