Rework how macros are declared. Add new keyword called macro that will have this syntax:
macro <identifier>(params...):
pass
Where identifier is macro name.
To fix member macros (that we cannot actually call the value itself, eg we cannot currently declare member macro in overpy and use input value used) we can add extra keyword specific to new macro syntax, self:
self will be a reserved word inside macro, no one can use that name.
New macro can both resolve statements/expressions and annotations.
macro isABot(self):
@Condition self.isDummyBot()
@Condition self.hasSpawned()
rule "test if we can teleport bot":
@Event eachPlayer
eventPlayer.isABot() // expand both conditions here, using `eventPlayer` as `self` argument.
Macro that return an value from macro, put inline instead newline + indent
Or add special check in return inside that macro, to use last line inside the macro as final expanded value. Example:
globalvar v1
globalvar v2
globalvar vf
macro asSafePos(v): nearestWalkablePosition(v)
macro safePos(v):
v1 = v + vect(-10, 0, -10)
v2 = v + vect(10, 0, 10)
return (v1 - v2).asSafePos()
rule "init safe pos":
vf = safePos(getObjectivePosition(0)) # expand all other actions, vf = expand all content of `return` line, after the keyword.
# all macros above will expand to:
v1 = getObjectivePosition(0) + vect(-10, 0, -10)
v2 = getObjectivePosition(0) + vect(10, 0, 10)
vf = nearestWalkablePosition(v1 - v2)
As well "static" macros, that don't use self in first argument:
Rework how macros are declared. Add new keyword called
macro
that will have this syntax:Where
identifier
is macro name.To fix member macros (that we cannot actually call the value itself, eg we cannot currently declare member macro in overpy and use input value used) we can add extra keyword specific to new macro syntax,
self
:self
will be a reserved word inside macro, no one can use that name.New macro can both resolve statements/expressions and annotations.
Another example using vector.
Macro that return an value from macro, put inline instead newline + indent Or add special check in
return
inside that macro, to use last line inside the macro as final expanded value. Example:As well "static" macros, that don't use
self
in first argument: