objD icon indicating copy to clipboard operation
objD copied to clipboard

Adding Function Arguments with Data Storage

Open Stevertus opened this issue 4 years ago • 2 comments

Originally created for mcscript by @WilliamRagstad here: https://github.com/Stevertus/mcscript/issues/23

There is a poly-fill trick for supporting arguments to functions using the new /data get storage [name] [path]. Format example:

mcscriptfunctions
|___ [function name]
        |___ [meta data]
        |___ [arguments]
               |___ [0]
               |___ [1]
               |___ ...
               |___ [N]

This will allow for real-time function calls if you create a macro that generates commands similar to the following code: (simulating using C#)

void callToFunction(string name, object[] args) {
   string r = "/data modify storage MCScriptFunctions " + name + ".arguments set value [";
   for(int i = 0; i < args.length; i++) r += args[i];
   r += "]\n"
   r += "/function " + name;
}

This could probably be optimized in many ways regarding to recursion etc (can be solved by storing arguments in temp variables), but this is the overall picture.

Stevertus avatar Sep 19 '20 11:09 Stevertus

I think this will no longer be necessary with the new macro feature in 23w31a.

scarzehd avatar Aug 06 '23 14:08 scarzehd

This could still be useful, but not precisely in this way. The new macro system still requires a lot of glue code to achieve somewhat dynamic behavior. I recommend watching this video by Cloud Wolf.

WilliamRagstad avatar Aug 09 '23 13:08 WilliamRagstad