Closed Nico314159 closed 1 year ago
In JavaScript, the x ??= y operator will assign x the value of y only if x is null. This is highly useful for setting default values of variables. To Minecraft-ify this, I propose that the syntax be:
x ??= y
x
y
$<variable> ??= <integer>; $<variable> ??= $<variable>;
which compiles down to
execute unless score <foo> <objective> = <foo> <objective> run scoreboard players set <foo> <objective> <integer>; execute unless score <foo> <objective> = <foo> <objective> run scoreboard players set <foo> <objective> = <bar> <objective>;
This would be useful for the same reason as in the original JavaScript, as initializing scoreboard variables is a common need.
Already set up a GitHub branch for this one too: https://github.com/Nico314159/jmc/tree/null-coalescing
Description
In JavaScript, the
x ??= y
operator will assignx
the value ofy
only ifx
is null. This is highly useful for setting default values of variables. To Minecraft-ify this, I propose that the syntax be:which compiles down to
This would be useful for the same reason as in the original JavaScript, as initializing scoreboard variables is a common need.