Henrybk / eventMacro

My personal rework of openkore's macro plugin
GNU General Public License v2.0
5 stars 5 forks source link

resolve special variables when they are used #68

Closed allanon closed 7 years ago

allanon commented 7 years ago

Currently, eventMacro updates special variables in parse_command, which is triggered for many but not all macro commands. Most lines which include such commands do not use the special variables, however, so we should resolve them only when needed.

This change allows us to add more special variables without increasing the cost of commands which do not use any special variables.

As an additional enhancement, the resolution of special variables could be done via a hash with coderefs to make resolving them a constant-time operation instead of linear-time. I didn't do that because I believe the code is clearer this way and we don't (currently) have a lot of special variables.

This was tested with the following eventMacros:

macro test {
  call test2
}

macro test2 {
  log map       : $.map
  log pos       : $.pos
  log time      : $.time
  log datetime  : $.datetime
  log hour      : $.hour
  log minute    : $.minute
  log second    : $.second
  log hp        : $.hp
  log sp        : $.sp
  log lvl       : $.lvl
  log joblvl    : $.joblvl
  log spirits   : $.spirits
  log zeny      : $.zeny
  log status    : $.status
  log param1    : $.param1
  log param2    : $.param2
  log caller    : $.caller
  log weight    : $.weight
  log maxweight : $.maxweight
}

... and the following command line:

eventMacro test -- a b c