-
-
Notifications
You must be signed in to change notification settings - Fork 379
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
Dynamic Functions #6254
Dynamic Functions #6254
Conversation
I like the idea of being able to call functions dynamically, but I'm hesitant to add functions as first-class objects. |
What do you suggest? I did it so the patterns are not too long with the ability to specify which script the function is declared in, and also it doesn't look pretty to shove everything into one pattern like so: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well done Tud ⚡ I like this feature
|
||
@Name("Execute Function") | ||
@Description("Executes a function with the given parameters.") | ||
@Examples("run function \"rotate_%{_direction}%\" with {_structure-name}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer having a more in depth example for this specific advanced feature, like add 2 functions with the possible names and params
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what you mean
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is an example which you can commit if you like :)
@Examples("run function \"rotate_%{_direction}%\" with {_structure-name}") | |
@Examples({ | |
"function rotate_north(structure: text):", | |
"\t# code", | |
"", | |
"function rotate_east(structure: text):", | |
"\t# code", | |
"", | |
"run function \"rotate_%{_direction}%\" with {_structure-name}" | |
}) |
} | ||
|
||
private static String formatScript(String script) { | ||
if (!script.endsWith(".sk")) script += ".sk"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (!script.endsWith(".sk")) script += ".sk"; | |
if (!script.endsWith(".sk")) | |
script += ".sk"; |
|
||
Object[][] params = new Object[singleListParam ? 1 : parameters.length][]; | ||
if (singleListParam && parameters.length > 1) { // All parameters to one list | ||
List<Object> l = new ArrayList<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use better naming here please.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just moved the validation code from FunctionReference and moved it here. I guess I could clean it up as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would be nice :)
that is the route i would take, but i would make it a few patterns. what would make the implementation messy? |
i think adding this would be useful, less lines to parse and probably an overall quicker way to run stuff. |
Closing due to inactivity and in favor of #6713 |
Description
This PR adds the long-awaited feature to Skript, dynamic functions! Functions are now objects that can be dealt with inside scripts with the new
function
type. To get a function object, you use theExprFunction
expression.Example:
You can even get local functions from other scripts, like so:
Using these objects you can execute or get the result of a function's execution dynamically, like so:
Target Minecraft Versions: any
Requirements: none
Related Issues: #1265