overpy icon indicating copy to clipboard operation
overpy copied to clipboard

Idea: Define member applied to specific types and new macro declarations prototype.

Open nathan130200 opened this issue 3 years ago • 2 comments

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 ` so we can call

Structure: #!defineMember <name> simple_expression|(complex expression) <type?> Where:

  • Simple expression return itself value: #!defineMember myX x Vector (create member myX on Vector that reflect to x 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 by myDummyBot
    • victim.tpToCenter() -> __this__ -> victim
    • Z.tpToCenter() -> error: Z is Variable, not Player type. Except if tpToCenter accept Object 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 using def 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.

nathan130200 avatar Jan 16 '22 18:01 nathan130200

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.

Zezombye avatar Apr 19 '22 15:04 Zezombye

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

nathan130200 avatar Apr 19 '22 19:04 nathan130200