I started working with the JavaScript Runtime, and I couldn't figure out how to use adventure() with a custom combat filter function defined in the same script. The function is never found, and thus always returns void. (Shouldn't it throw an error if the requested function is not found? Ash seems to do that from looking at the code, but the wiki for adventure() says otherwise)
So I dug around the code a bit, and it seems that the JavascriptRuntime always searches the topLevelScope for exported functions. However, the functions exported by the main module are not merged into the global context, and are thus lost after the top-level execution.
I tried this change, and now I can use locally defined functions as combat filter functions.
Can anybody with some knowledge of the Javascript runtime give me a hint if this is the right way to go, or am I missing something?
Is there any good use case for looking up the function name in the top level scope (here)?
I also had a problem that run_combat always returns void, because the engine state is always EXIT (perhaps because of the filter function
). I tried to re-set the engine state during non-top-level executions, but without much success. Any ideas?
So I dug around the code a bit, and it seems that the JavascriptRuntime always searches the topLevelScope for exported functions. However, the functions exported by the main module are not merged into the global context, and are thus lost after the top-level execution.
I tried this change, and now I can use locally defined functions as combat filter functions.
Can anybody with some knowledge of the Javascript runtime give me a hint if this is the right way to go, or am I missing something?
Is there any good use case for looking up the function name in the top level scope (here)?
I also had a problem that run_combat always returns void, because the engine state is always EXIT (perhaps because of the filter function
