dr-scripts icon indicating copy to clipboard operation
dr-scripts copied to clipboard

[scripts][trigger-watcher] - Create Lich-based Triggers

Open asechrest opened this issue 2 years ago • 8 comments

Creates a concept of Lich-based triggers and responses. Triggers are built in a yaml file. Currently a work in progress. (Now ready for review.)

Relies on #5889

asechrest avatar Jul 03 '22 14:07 asechrest

Had a couple of folks ask if they could mess around with this. This is like super alpha release and you'll see tons of spammy code comments still in here. But if you still want to play:

You'll need a couple additional things:

The below yaml can now live in either -setup.yaml or in Charname-triggers.yaml. Note, now need a heading line of lich_triggers:.

~~- A yaml called base-triggers.yaml. Copy and paste the below in a file of that name and put in \scripts\data for now.~~ ~~- PR #5889 which adds a method to common to log to any window name you specify. Throw in your \custom folder.~~

# LICH TRIGGERS
# Yaml for Lich-based triggers

####################################################################################################
# =exec - "execute" - Execute a script
#   =exec <script> <arguments>
# =execw - "execute wait" - Execute script and wait for it to end
#   =execw <script> <arguments>
# =uvar - "user variable" - Set or delete a user variable based on a trigger
#   =uvar set <VarName> <value>
#   =uvar delete <VarName>
#   - (Reference a user variable in a trigger response via $<VarName>)
# =logf - "log file" - log to a file in the Lich file tree
#   =logf <FileName> <Text to log>
# =logw - "log window" - log to a window in the FE
#   =logw <WindowName> <Text to log>
# =reload - live reload of yaml trigger data
####################################################################################################

lich_triggers:
  stand:
    triggers:
      - (\w+) sit down
    responses:
      - =logf assaults Text that we want $1
  peering_up:
    triggers:
      - (\w+) up from the (\w+) of the (\w+)
    responses:
      - say $2
      - whisper $Test1 $Test2

asechrest avatar Jul 03 '22 17:07 asechrest

@rpherbig @MahtraDR

I'm switching this from draft to ready for review. I'm going to try to recruit some testers but in the meantime if ya'll could look through the code and see what you think. Would like to hold off on merging for a while longer.

There is also a work in progress wiki page that will accompany this: https://github.com/rpherbig/dr-scripts/wiki/Lich-Triggers

Triggers can live in the -setup yaml or in a separate yaml named Charname-triggers.yaml. Format as follows:

lich_triggers:
  regex_sub_test:
    triggers:
      - You are (.*) years old
    responses:
      - say I am $1 years old
  trigger_reload: # Live reload of triggers. Trigger this by typing into game 'echo reload my triggers`
    triggers:
      - reload my triggers 
    responses:
      - echo reloading
      - =reload

Currently available trigger commands: https://github.com/rpherbig/dr-scripts/wiki/Lich-Triggers#trigger-commands

Thanks.

asechrest avatar Jul 10 '22 16:07 asechrest

Currently have a critical bug in the script, so not ready for merge.

asechrest avatar Jul 13 '22 18:07 asechrest

With the help of @rcuhljr I fixed the critical bug in the script. It stemmed from a fundamental misunderstanding of how Ruby handles references to an object, and the issue was that I thought I was "copying" an array to a variable, but really it was pointing to the same reference and was permanently modifying the array. Just one of those things where a non-pro doesn't realize it, but a true dev would.

Anyway, this is ready for final testing now. I've posted on Discord, and also I think @MahtraDR is going to help me test.

asechrest avatar Jul 30 '22 17:07 asechrest

Testing going fantastic. Limited only by my imagination and I'm very creative. No bugs yet.

Given it's a new script, let's merge and deal with bugs as they arise?

MahtraDR avatar Jul 31 '22 01:07 MahtraDR

Couple small commits. Being a little more verbose when live reloading triggers, and removing some spammy feedback now that the script is mostly finalized.

asechrest avatar Jul 31 '22 14:07 asechrest

The issue of nested code aside, this works fantastically for me.

The "issue" is that I can't seem to have a trigger that parses variables, which honestly... might just be beyond scope?

MahtraDR avatar Jul 31 '22 23:07 MahtraDR

The issue of nested code aside, this works fantastically for me.

The "issue" is that I can't seem to have a trigger that parses variables, which honestly... might just be beyond scope?

Can you give an example of what you want? As you know I'm already thinking about some ways to expand functionality, so just want to fully understand what you're thinking about.

asechrest avatar Aug 01 '22 00:08 asechrest

Moving to draft again as I do a final push for full code execution functionality in trigger responses.

asechrest avatar Aug 21 '22 22:08 asechrest

Now putting this back to ready for review. The final push of changes does the following:

  • By convention now, all trigger commands need to be wrapped in curly braces. Example: =eval {#code to eval}
  • Trigger responses now allow embedded code. If you want to embed code, wrap the code in curly braces. Example: - =uvar {set RoomOccupants {DRRoom.pcs}}
  • I've now implemented a use_with_scripts option. If specified, the trigger will only fire if one of the specified scripts are running. This feature is by request of @Smaptastic .

asechrest avatar Sep 03 '22 17:09 asechrest

@asechrest I'm on the latest version, and it's great to me. I'm happy to merge this if you are.

MahtraDR avatar Sep 04 '22 01:09 MahtraDR

@asechrest I'm on the latest version, and it's great to me. I'm happy to merge this if you are.

This sounds good. I also updated the work-in-progress wiki for triggers. I can make an announcement in Discord.

asechrest avatar Sep 04 '22 01:09 asechrest