Custom effects and expressions with skript-mirror
As of skript-mirror 0.8.0, you can now create your own custom effects and expressions. These serve as a replacement for Skript functions with more features and more familiar syntax.
By combining custom syntax with reflection, it is now possible to extend Skript in ways previously only achievable through addons. In fact, in many cases, it is better to use skript-mirror's custom syntax instead of creating an addon:
Let's start by creating a simple effect:
Notice, we can use the same Skript features, like [brackets] and (curvy brackets|parentheses).
We can even use expressions:
And if we want, we can accept multiple expressions as input. Notice how the type parameter is strings and we use expressions-1 instead of expression-1.
Running /tutorial2 Alice Bob prints "Hello, Alice" and "Hello, Bob".
We can even use waits and delays:
However, this example prints "Hello", "end", then "World". This is because Skript is not waiting for the effect to complete before it continues with the following code. (This is how functions behave, too.)
In order to fix this, we must indicate that the effect will be delayed before the delay occurs. We must also add continue at the end to indicate that the effect has ended and the code can continue to execute.
This prints "Hello", "World", "end", as you might expect.
You may notice we now have a greet [the] world effect and a greet [the] world slowly effect. We can combine the logic for these two effects into a single effect using parser marks.
Notice, the latter branch of the if statement does not need a continue because it never reaches a line that delays the expression.
Expression tutorial coming soon. For now, you can read this tutorial for a taste of expressions.
By combining custom syntax with reflection, it is now possible to extend Skript in ways previously only achievable through addons. In fact, in many cases, it is better to use skript-mirror's custom syntax instead of creating an addon:
- Custom syntax is hot-reloadable (reloadable without restarting the server), just like other Skript features
- Custom syntax does not require a compiler
- It is much easier to achieve high quality standards—the learning curve is much smaller!
Let's start by creating a simple effect:
effect greet [the] world:
broadcast "Hello, world!"
command /tutorial1:
trigger:
greet world
greet the world
broadcast "Hello, world!"
command /tutorial1:
trigger:
greet world
greet the world
Notice, we can use the same Skript features, like [brackets] and (curvy brackets|parentheses).
We can even use expressions:
effect greet %string%:
broadcast "Hello, %expression-1%"
broadcast "Hello, %expression-1%"
And if we want, we can accept multiple expressions as input. Notice how the type parameter is strings and we use expressions-1 instead of expression-1.
effect greet %strings%:
loop expressions-1:
broadcast "Hello, %loop-expression%"
command /tutorial2 <text>:
trigger:
greet argument split by " "
loop expressions-1:
broadcast "Hello, %loop-expression%"
command /tutorial2 <text>:
trigger:
greet argument split by " "
Running /tutorial2 Alice Bob prints "Hello, Alice" and "Hello, Bob".
We can even use waits and delays:
effect greet [the] world slowly:
broadcast "Hello"
wait 5 seconds
broadcast "World"
command /tutorial3:
trigger:
greet the world slowly
broadcast "end"
broadcast "Hello"
wait 5 seconds
broadcast "World"
command /tutorial3:
trigger:
greet the world slowly
broadcast "end"
However, this example prints "Hello", "end", then "World". This is because Skript is not waiting for the effect to complete before it continues with the following code. (This is how functions behave, too.)
In order to fix this, we must indicate that the effect will be delayed before the delay occurs. We must also add continue at the end to indicate that the effect has ended and the code can continue to execute.
effect greet [the] world slowly:
delay the effect
broadcast "Hello"
wait 5 seconds
broadcast "World"
continue
command /tutorial3:
trigger:
greet the world slowly
broadcast "end"
delay the effect
broadcast "Hello"
wait 5 seconds
broadcast "World"
continue
command /tutorial3:
trigger:
greet the world slowly
broadcast "end"
This prints "Hello", "World", "end", as you might expect.
You may notice we now have a greet [the] world effect and a greet [the] world slowly effect. We can combine the logic for these two effects into a single effect using parser marks.
effect greet [the] world [(1¦slowly)]:
if parse mark is 1:
delay the effect
broadcast "Hello"
wait 10 seconds
broadcast "World"
continue
else:
broadcast "Hello, world!"
if parse mark is 1:
delay the effect
broadcast "Hello"
wait 10 seconds
broadcast "World"
continue
else:
broadcast "Hello, world!"
Notice, the latter branch of the if statement does not need a continue because it never reaches a line that delays the expression.
Expression tutorial coming soon. For now, you can read this tutorial for a taste of expressions.