overpy
overpy copied to clipboard
Idea: Define member applied to specific types and new macro declarations prototype.
TL;DR
An way to declare arguments in #!defineMember like macros, introducing (new keyword? "macro") or using subroutines like declaration def
, with explicit types where macro should apply.
Detailed
New feature that will have 3rd param in #!defineMember
Structure:
#!defineMember <name> simple_expression|(complex expression) <type?>
Where:
- Simple expression return itself value:
#!defineMember myX x Vector
(create membermyX
onVector
that reflect tox
component) - Complex expression Function call, conditional checks, etc:
-
#!defineMember isValidPlayer (__this__.isAlive() and not __this__.isDummy()) Player
-
Example:
#!defineMember tpToCenter (teleport(__this__, vect(0, 0, 0))) Player
- The static
__this__
will refer who is calling that macro and will replace value. Examples:-
myDummyBot.tpToCenter()
value in__this__
will be replaced bymyDummyBot
-
victim.tpToCenter()
->__this__
->victim
-
Z.tpToCenter()
-> error:Z
isVariable
, notPlayer
type. Except iftpToCenter
acceptObject
type, that means a generic value.
-
Another example:
-
#!defineMember isBetterTargetToKill (__this__.getNormalizedHealth() <= 10) Player
, since its a complex call, we must put inside on(
...expression
...) <type?> (optional)
And if possible declaring params like virtual functions in #!defineMember
or new preprocessor
macro keepOnPayload(Player, forceRespawn):
if self.isDead() and forceRespawn:
self.respawn()
self.teleport(getPayloadPosition())
Notes
- Instead of
macro
keyword can be same way in subroutines usingdef
keyword. - For
def
can have annotation@Macro
to identify as macro, so if not@Name
isn't subroutine - Can also allow developer changing name of param to use in function declaration
keepOnPayload(self: Player):
like in python typpings.
Where self
is value to current 'injected' value. In this example self
refer to player that invoked. self
= eventPlayer
for example.
So we can attach and call dynamic macro that will be translated as actions:
rule "respawn bot if needed":
@Event eachPlayer
@Condition eventPlayer.isDead()
@Condition eventPlayer.isDummy()
eventPlayer.keepOnPayload(true)
wait(1)
goto RULE_START
- I know that exist javascript source generator, but sometimes makes difficulty because makes a bit confusion in indentation problems, from source generated to compiling.
- Maybe can be an enhancement not just for defineMember, but also preprocessor calling.
I forgot to reply but this is basically the AST macro thing I've had in my head for a while (I made a mistake following C's path, lul)
I think I will replace #!defineMember
by "A.B", basically if the define name has a dot, assume the first member is the type and the second is the name.
The multi-line macros will use inline def
, however I gotta think about the single-line macros, I thought about inline lambda somefunc(x): x+2
but it clashes with python's lambda syntax where the function name isn't specified. And for constants, inline const DEBUG_MODE = true
.
Thanks for reply, yeah i suggest for some complex macros that we must transfer variable name to invocation.
For example #!defineMember isPlayerValidForScoring(condition) eventPlayer.someVar == true
we can use eventPlayer
as usually but when i will invoke this macro on attacker
/victim
values will not work.
So for replacement we can transfer direct variable name #!defineMacro myFunc(param1, param2) this.param3 = [param1, param2]
where this.
is everything before .
after invoke this macro.
So: eventPlayer.botEntity.myFunc(1, 2)
, this.
will be translated as eventPlayer.botEntity
Or something similar to match with overpy syntax.
Also offtopic/non related to this suggestion is declare temporary variable names for for loop
reserve an global/player variable called _opyForLoopIndexex
when all non declared variables to for loop will automatically grab an index, then use While(...)
and End;
to peform an looping. Its like OSTW does but more simple