-
Notifications
You must be signed in to change notification settings - Fork 0
DSL : statements
A statement is an instruction. All statements are executed one after another. Statements must end with a ;.
You can create "blocks" by placing multiple statements between curcly braces ({}).
Keywords in squared-brackets [] are optional. Expressions (i.e. arguments) are between chevrons (<>).
Define a new variable, or redefine an existing one. Only applies to the current scope.
Syntax : define <VAR> = <VALUE>
-
VARis the Variable to define. Must be of the format%<name>. -
VALUEis an Expression of any type. - Following this statement,
<VAR>will be a variable accessible to all other statements, for the current scope.
Example:
define %var = 12;Increment or decrement a numeric variable.
Syntax: increment <VAR> or decrement <VAR>
- VAR the Variable to respectively increment or decrement by one.
Examples:
define %i = 12;
increment %i; # i = 13
decrement %i; # i = 12;Stop the current execution. Must be the last statement of a scope.
Syntax: stop [<RETURN_CODE>] :
- RETURN_CODE : an optional *Number, equal to 0 by default. If any other number, the spell will be considered as failed.
Example:
# Stop the execution in success
stop;
# Stop it with an error code
stop 42;Note: In reality, this example does not compile, as it is not possible to have a statement following a stop.
Classic conditional branching.
Syntax: if(<CONDITION>) <ST_TRUE> [else <ST_FALSE>]
-
CONDITIONan Expression of type Boolean. -
ST_TRUEthe statement to execute if the condition evaluates to true. -
ST_FALSEthe statement to execute otherwise.
Note: Obvisouly, you can put another if in a else statement, thus obtaining else if statements.
Example:
if(%var <= 12 || %foo != 0) {
...
} else if(%bar == %toto) {
...
} else {
...
}Classic ranged-iterative statement.
Syntax: for(<ST_INIT>; <CONDITION>; <ST_ITERATION>) <ST>
-
INITa Statement to do at the beginning of the FOR. -
CONDITIONan Expression of type Boolean. -
ST_ITERATIONthe statement to after all iteration. -
STthe statement execute on each iteration.
Example:
for(define %i = 0; i < 3; increment %i) {
...
}Classic conditional loop statement.
Syntax: while(<CONDITION>) <ST> or do <ST> WHILE(<CONDITION>)
-
CONDITIONan Expression of type Boolean. -
STthe statement execute on each iteration.
Example:
define %var = 2;
# While (do)
while(%var > 0) {
decrement %var;
}
# Do, while
do {
increment %var;
} while(%var < 2);Iterative loop over a collection.
Syntax: foreach(<VAR_ELEM> : <COLLECTION>) <ST>
-
VAR_ELEMa Variable to hold the content of the current iteration. -
COLLECTIONa Collection of elements. -
STstatement to be executed for each value.
Example:
foreach(%monster : %monsters) { # You'll see later how to create / obtain collections
...
}Classic control-flow elements.
- The
breakkeyword will stop the loop. - The
continuekeyword will stop the current loop-iteration.
Both work for all loop statements (for, while, foreack, repeat).
Sometimes, you want to either do something after a while, or repeat it for a duration.
A way executing statements after a delay.
Syntax: run after <DELAY>: <ST>
-
DELAYis a Duration. -
STis a Statement to execute after the delay.
Example:
run after 4 seconds: {...}
run after 42s: {...}Run an action periodically for a duration, with an optional initial delay.
Syntax: repeat [after <DELAY>] <COUNT> times every <PERIOD>: <ST> : run a statement repeatedly after an optional delay.
-
DELAYis a Duration. -
COUNTis a Number. Any non-integer value will be rounded to one. -
PERIODis a Duration. -
STis a Statement to execute times.
Alternative: repeat [after <DELAY>] every <PERIOD> for <DURATION>: <ST> : with DURATION the total duration.
Example:
repeat %count times every 0.5 minutes: {...} # run every 30 seconds
repeat after 3s 12 times every 1m: {...} # run 12 times every minute, after an initial delay of 3s.Run an action when a summoned entity his part of a Bukkit event. An argument specific to the event can be used.
Syntax: callback <ENTITY> <TYPE> [<KEYWORD> <ARGUMENT_VAR>]: <ST>
-
ENTITYis a Summoned entity. -
TYPEis a custom callback type. Check the corresponding documentation for the complete list. -
KEYWORDis a String or custom, matching thetype. Check the doc. -
ARGUMENT_VARis a Variable to store the argument value to. -
STis a Statement to execute when the event triggers.
Example:
# First, summon a projectile with the SUMMON statement. Saved in the %projectile var.
# Teleport the caster to the landing location
callback %projectile LANDED at %pos: {
teleport %caster to %projectile;
}
# Or send a message when the projectile expired instead of landing.
callback %projectile expire: {
send %caster message "Projectile expired :(";
}Now that we can control variables and control the flow of the spell exection, let's act on the world !
Note that, in general, one of the philosphy here is to not impact the world durably. All modifications are either transient, or limited to a duration.
Send a text-message to a player.
Syntax: send [to] <TARGET> message <CONTENT>;
-
TARGETis an Entity. Can be a list. -
CONTENTis a String, content to be sent to the target. Can be a list.
Note: The content in the string will evaluate the variables expressions (without having to concatenate the string).
Examples:
send to %caster message "I &d&lLOVE&f apples."; # Colors are classic, with a '&' character.
send to %caster message "You are %caster"; # Will print the caster's name.Send an potion effect to an entity.
Syntax: send [to] <TARGET> effect <EFFECT> [<POWER>] for <DURATION>;
-
TARGETis an Entity. Can be a list. -
EFFECTis a EffectTypeWill change to accept any string.
-
POWERis a Number, -
DURATIONis a Duration.
Example:
send to %caster effect STRENGTH 3 for 12 secs;
send to %caster effect glowing for 1m;Send a transient attribute to an entity, for a duration.
Syntax: send [to] <TARGET> attribute <VALUE> <ATTRIBUTE_TYPE> [<MODE>] for <DURATION>;
-
TARGETis an Entity. Can be a list. -
VALUEis a Number : the amount of attribute to add/remove. -
ATTRIBUTE_TYPEis a String, but must reference an Attribute. You can skip the prefixes (likeGENERIC_). -
MODEoptional operation for the attribute modifier. It's a String but must reference an AttributeModifier.Operation. Will beADD_NUMBERif not set. -
DURATIONis a Duration.
Example:
# +3 armor for 15 secs
send to %caster attribute 3 ARMOR for 15000ms;
# - 50% model scale for 10 secs
send %caster attribute -0.5 "SCALE" "MULTIPLY_SCALAR_1" for 10s;Summon an entity.
Syntax: summon <TYPE> [at <POS>] [as <VAR>] for <DURATION> [with: <PROPERTIES>]
-
TYPEis an EntityType for the summoned entity. -
POSis the location for the summon to spawn. Can be an Entity or a Location.- Note: If nothing is provided, will spawn on the caster.
-
VARis the optional Variable to store the newly created entity. -
DURATIONis the duration of the summon, after which it will be removed. -
PROPERTIESa property set defining all attributes for the summon. Check the summon attributes documentation for more information.
Example: Check the documentation or this example.
Teleport an Entity to a position.
Syntax: teleport <ENTITY> to <TARGET>
-
ENTITYis an Entity. Can be a list. -
TARGETis an Entity or a Location to teleport the entity to.
Example:
# Teleport the caster 100 blocks up.
teleport %caster to ((position of %caster) + [[0, 100, 0]]);Play an effect to a position.
: Play an effect at a position, with some attributes. > Example 1: ``
Syntax: play <ACTION> AT <POS> WITH: <ATTRIBUTES>
-
ACTION: Can be eitherparticle,soundorblock. -
POS: a Location (or Entity) to play the effect at. Can be a list. -
ATTRIBUTES: A property set to specify more data. Check the play documentation for more informations.
Example:
play particle at %caster with: {{ type: FLAME, count: 12, speed: 0.2 }};
play sound at %caster with: {{ type: BLOCK_BEACON_ACTIVATE, volume: 0.6, pitch: 1.1 }};
play block at %caster with: {{ type: GRASS_BLOCK, duration: 0.6 minutes }};
play animation at %caster with: {{ id: "explode.items", duration: 3s, count: 3, types: [[ "stone", "redstone" ]] }};Give an item to a player.
Syntax: give [[<AMOUNT>] <TYPE>] TO <TARGET> [WITH: <PROPERTIES>]
-
AMOUNT: optional Nuber (if<TYPE>is specified). Default value is1. -
TYPE: optional String, matching a Material. -
TARGET: of type Entity, recipient of the item. Can be a list. -
PROPERTIESoptional properties set. Check thesummonstatement for more links. May override theAMOUNTandTYPEarguments.
Example:
give 3 APPLE to %caster;
give TO %caster with: {{type: APPLE, name: "&dSuper apple"}}