Code Monkey home page Code Monkey logo

Comments (1)

obiwankennedy avatar obiwankennedy commented on June 21, 2024

There are 2 methods of substitution to transform macro to real command.
The last parameter of macro adding command defined the method you want.

# Method 1 - Find and replace (when you put False at the end)

The first substitution mode is very simple. It is simple find and replace. It is up to you to find solution and to use pattern which will only be present once in your command.

Each macro is tested in the order of appearence when you send !macro list command.

Example:

If you have these 3 macros (in that order):

  • s => +20
  • i => +1d6
  • o => i:[>20]{"Success"}{"Failure"}

If you roll:

  • !1d6s it will become => !1d6+20
  • !1d6i it will become => !1d6+1d6
  • !1d6is it will become => !1d6+1d6+20
  • !4d6o it will become => !4d6i:[>20]{"Success"}{"Failure"}

Now, you add these 3 macro (in that order):

  • o => i:[>20]{"Success"}{"Failure"}
  • s => +20
  • i => +1d6

If you roll:

  • !1d6s => !1d6+20
  • !1d6i => !1d6+1d6
  • !4d6o => !4d6i:[>20]{"Success"}{"Failure"} => !4d6i:[>20]{"Succe+20+20"}{"Failure"} => !4d6+1d6:[>20]{"Succe+20+20"}{"Fa+1d6lure"}

This method is really simple and perfect if you have no changing part or if the changing part of your command is at the beginning or the end of your command.

  • K => d10e10k # old L5R system

in game:
!6K4 => 6d10e10k4

The 6 is number of roll dice and the 4 is the number of kept dice. In this case we are lucky there are at the beginning and the end of the command.

As you see the order of command can help but in some cases it is simpler to use the second method.

# The second method - Regular expression

Regular expressions are a standardized way to find pattern in text.
Basically you can say: "If the command starts with a number, then it must be a W, after that another number following by a comma and at the end it must another number, in this case the macro is triggered.".
So regular expression allows you to make real complex pattern in order to make sure the substitution will take place in when it should.

Example:
!macro add ([0-9]+)W([0-9]+),([0-9]+) \1d10e[>\2]+\3 True
Usage:
!8W6,2 => 8d10e[>6]+2

As you see, in this case we have changing part at the beginning, at the end and in the middle (the 6).
In that case, it is important to use the regular expression method to replace \2 by the 6.

# In your case:
Let's define some of your macro with regular expression:

!macro add ^([0-9]+)s$  \1d10;1d10;$1c[>=$2];"DL $2 | rolls [@1] | successes $3" True

Then:
!3s => 3d10;1d10;$1c[>=$2];"DL $2 | rolls [@1] | successes $3"

## Won't work (I mean the substitution won't work but if the command is a valid one, it will run them)
!3s+2
!8d10s;"Sorted: @1"


!macro add ^(.*)o$ \1;$1i:[<=4]{" dodge failed"}{$1i:[5..7]{" weak dodge"}{$1i:[8..12]{" successful dodge"}{$1i:[>=13]{" critical dodge"}}}} False

Then:

  • !1d14+2o => 1d14;$1i:[<=4]{" dodge failed"}{$1i:[5..7]{" weak dodge"}{$1i:[8..12]{" successful dodge"}{$1i:[>=13]{" critical dodge"}}}}
  • !d14o => d10;$1i:[<=4]{" dodge failed"}{$1i:[5..7]{" weak dodge"}{$1i:[8..12]{" successful dodge"}{$1i:[>=13]{" critical dodge"}}}}

from diceparser.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.