Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Function Arguments with Data Storage #15

Open
Stevertus opened this issue Sep 19, 2020 · 2 comments
Open

Adding Function Arguments with Data Storage #15

Stevertus opened this issue Sep 19, 2020 · 2 comments
Labels
suggestion suggestion

Comments

@Stevertus
Copy link
Owner

Originally created for mcscript by @WilliamRagstad here: Stevertus/mcscript#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 Stevertus added the suggestion suggestion label Sep 19, 2020
@scarzehd
Copy link

scarzehd commented Aug 6, 2023

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

@WilliamRagstad
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
suggestion suggestion
Projects
None yet
Development

No branches or pull requests

3 participants