For my project, I have callable objects (arbitrary NBT dict that is theoretically capable of calling an mcfunction) stored on an NBT array (the Stack).
At an arbitrary time in execution I want to be able to pop the callable off the Stack and somehow use it to call a function.

My original thought was to just store a string like "function ns:fn_name" and then data modify... that string into a command block and run it.
Problem is, command blocks execute on the next tick and there seems to be no way around this.

My next thought would be to have an invoker function that contains every possible function call, and a chain of execute if data stack[0]{name:<function_name>} run function ns:<function_name>, where stack[0] is the callable at the top of the stack, and the callable would store the name of its desired function in callable.name.

My problem with this is efficiency. For the number of defined functions n, it's potentially adding n checks every function call and that sucks.

However, I can't think of a better way to call an arbitrary function like this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.