• Hello game master! Welcome to our growing community. Please take a moment to Register (top right button, see how: Slides).

    If you use Campaign Logger, you can use the same login details - we've linked the app to this forum for secure and easy single sign-on for you.

    And please drop by the Introductions thread and say hi.

Math in generators? vars working inconsistently?

devonapple

New member
Is it possible to do math in a generator using variables?

Example:
  1. 'tableA' returns a 'value', and that value has an associated number titled 'rank'.
  2. 'tableB' returns 'another value' and that value has an associated number titled 'multiplier'.
  3. I want to say "{tableA:value} holds {tableA:rank * tableB:multiplier} containers of {tableB:another value}".
Is this kind of variable operation used in any of the existing generator objects?

I read the documentation, and I felt there was a missed opportunity to explain more about why and how to use variables. It could also be my own knowledge gap!

Also, I figured out basic variables, but some of my var declarations break the compiler when I use them in the Results Pattern. I get an error that says:
`[ResultPattern] <error calling non-existent variable 'locationSearchedArticle' from ''>`

I'm not sure why some text-based vars like `locationScaleArticleLower` and `locationSearchedArticle` break the compiler.
 

Attachments

  • scavengingLocation.json
    4.5 KB · Views: 1
Last edited:

JochenL

CL Byte Sprite
Staff member
Adamantium WoA
Wizard of Story
Wizard of Combat
Gamer Lifestyle
Borderland Explorer
Math is a bit tricky as it only calculates variables when assigning to variables, but this should do what you want:

JSON:
{
    "name": "Example Variable Math",
    "resultPattern": "{start} holds {var:count} containers of {var:another_value}",
    "tables": [
        {
            "variables": {
                "count": 0
            },
            "entries": [
                {
                    "m": 1,
                    "v": "{tableA}{tableB}",
                    "set": {
                        "count": {
                            "v": "{math:{var:rank}*{var:multiplier}}"
                        }
                    }
                }
            ],
            "name": "start"
        },
        {
            "variables": {
                "rank": 0
            },
            "entries": [
                {
                    "m": 1,
                    "v": "Value a.1",
                    "set": {
                        "rank": {
                            "v": "1"
                        }
                    }
                },
                {
                    "m": 1,
                    "v": "Value a.2",
                    "set": {
                        "rank": {
                            "v": "2"
                        }
                    }
                },
                {
                    "m": 1,
                    "v": "Value a.3",
                    "set": {
                        "rank": {
                            "v": "3"
                        }
                    }
                }
            ],
            "name": "tableA"
        },
        {
            "variables": {
                "multiplier": 0,
                "another_value": ""
            },
            "entries": [
                {
                    "m": 1,
                    "v": "",
                    "set": {
                        "multiplier": {
                            "v": "1"
                        },
                        "another_value": {
                            "v": "Another Value b.1"
                        }
                    }
                },
                {
                    "m": 1,
                    "v": "",
                    "set": {
                        "multiplier": {
                            "v": "2"
                        },
                        "another_value": {
                            "v": "Another Value b.2"
                        }
                    }
                },
                {
                    "m": 1,
                    "v": "",
                    "set": {
                        "multiplier": {
                            "v": "3"
                        },
                        "another_value": {
                            "v": "Another Value b.3"
                        }
                    }
                }
            ],
            "name": "tableB"
        }
    ]
}
 

JochenL

CL Byte Sprite
Staff member
Adamantium WoA
Wizard of Story
Wizard of Combat
Gamer Lifestyle
Borderland Explorer
Also, I figured out basic variables, but some of my var declarations break the compiler when I use them in the Results Pattern. I get an error that says:
`[ResultPattern] <error calling non-existent variable 'locationSearchedArticle' from ''>`

I'm not sure why some text-based vars like `locationScaleArticleLower` and `locationSearchedArticle` break the compiler.
The best way to make sure a variable is defined is to add a "variables" property to a table and assign all variables (that are set by the table) a sensible defaults. (You can see an example of this in the source code I posted above.)
 
Top