edited March 2016 in ORK Support
What is the best way to set up a formula to simulate rolling (and adding up) multiple dice? For example, 3d6 or 4d6.

Obviously I could create a formula that generates 1-6 three times and adds them, another than generates 1-6 four times and adds them, etc. But that seems like a lot of tedious work to me. Is there any way of simply being able to specify the number and type of dice to roll?

While on the topic of random numbers, for the Random Value formula step, if I have the "int" checkbox set, then I have to specify a range of 1 to 7 in order to be able to generate a number from 1 to 6 (inclusive). Is this correct?
Post edited by Keldryn on
  • edited March 2016
    Using the Random Value step with As Int will just int cast the random value result (i.e. 5.8 will become 5) - which means that to get 6, you should probably use a value like 6.9 as 2nd value. If you use 1 to 7, there's still a (very very very) low chance of landing 7 directly.

    However, the problem would be that each value doesn't have the same chance to be cast (i.e. not exactly a dice) without a good setup. Best would be to use a Random Value step without As Int with value between 0.5 and 6.49999... and using a Rounding step using Round, or a random value between 1 and 6.99999... with a Floor rounding afterwards.
    Just use whatever method you want (e.g. Random step or a Chance Fork step with defined values afterwards), pack it into a formula for 1 dice. Once you have the 1 dice formula, you can use a Value step with the value type Formula to use your dice cast in a single step.
    Post edited by gamingislove on
    Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
  • Thanks, @gamingislove. I didn't know that Random Value just cast the result to an int; I thought that for some reason the upper bound wasn't being treated as part of the range. Makes sense now.

    The Random step has equal chances to generate each result attached to it, correct?

    One additional question related to this: What is the best way to assign a specific damage range to a weapon? A longsword that does 1-8, a dagger that does 1-4, a greatsword that does 2-12 (2d6) and that sort of thing. I was able to accomplish this by creating status values for the Number of Dice and Damage Die Type for the currently equipped weapon, with the weapon setting a custom bonus for those two status values, but that seems like a really clunky way to do it.
  • @Keldryn

    What I did was create two status values named minDMG and maxDMG and set them as hidden.
    Then, under the Status Value Bonuses section for your weapon, I added the two new statuses and set the min (1) and max (8) (from your longsword example).

    Finally, I have 3 formulas that I use for my melee damage calculations:
    1. minDamage - gets the user's current minDMG
    2. maxDamage - gets the user's current maxDMG
    3. STRDamage - I use the Random Value node and set Value 1 to use formula and select the minDMG formula. I set Value 2 to use a formula and select the maxDMG formula. I, also, add a bonus for higher Strength score of the user which is another formula :)


    This has worked out pretty good for both the player characters as well as the monsters
  • What @keyboardcowboy said is a good example. Similar, you can use the new Selected Data and Equipment Variables feature of ORK 2.7.0 in a similar way. See this how-to for details on selected data, and this gameplay tutorial for an example.
    Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
  • Thanks guys! I got it working the way I want it to now. Selected Data and Equipment Variables is the way to go for this, as I hate cluttering up my Status Values with this sort of thing (I've already got a lot in there as it is).
  • Hey @Keldryn can you either post here how you accomplished this with the weapon or PM me?

    What I can't figure out is how to access variable data using Selected Data in a formula.

    So for example, basic d20 rules, a shortsword causes damage of 1d4
    So in the Inventory->Weapons->Shortsword I create two game variables: NumDie (1), and NumSides (4)

    Now I move onto my formula: "Calculate Damage". Now sure - you can select equipment, but so what? What do we do with it?

    The other option i figured out was to grab an "NumDie" as an initial value, and store it, then Do a "Game Variable Fork" on NumSides, and for each option (4, 6, 12, 20, etc), call the appropriate formula (ie "Roll d4"), store (add) the value in a local GV, return to the beginning of the loop where we decrement the init value by 1, check to make sure its greater than 1, and do it all again.
  • @chud575, no problem, here you go:

    Here's the overall flow of my Calculate Melee Damage formula:

    image

    I'll briefly outline the steps:

    1. Select Equipment

    image

    This is where you get and store your selected data (the weapon).

    2. Game Variable Fork (check number of dice)

    image

    I wasn't giving weapons more than 2 base damage dice, so I didn't bother making this more efficient. If you use Change Game Variables, you can specify Variable Origin: Selected, but I don't know what the scope of the variable you are setting is, so I didn't simply store the numDice value as a local variable.

    3. Change Game Variables (store number of dice)

    image

    (And do the same for 1 die, obviously). We'll use this as the loop counter.

    4. Game Variable Fork (check type of die)

    image
    image

    (And so on)

    5. Add Value (for each die type)

    image

    Do this for each condition in 4. I Created separate formulas for each die type as I used them in many other formulas.

    6. Change Game Variables (decrease the loop counter by one)

    image


    7. Check Game Variables (number of dice)

    image

    If there are no dice left to add, exit the loop.

    8. Add damage modifier

    image

    Add the result of another formula that calculates the damage modifier based on strength, etc.

    Let me know if you have any questions.
  • @Keldryn you are the bomb my man.

    Okay so 2 questions / problems:

    1. When we call 'select equipment', and set the Selected Key value to 'weapon', we are doing that specifically for use inside the formula, correct? It's like assigning the data container of the actual weapon (short sword, axe, etc) and giving it a variable name?

    2. I'm having trouble accessing my variables from my weapon. I have a short sword, and inside the short sword are 2 variables 'DamageDieNum' (1) and 'DamageDieSides' (4). I tried setting one as a Game Variable, and the other as a value, not sure how thats really different in this circumstance. As a test, I simply have 2 nodes:
    - Select Equipment
    - Value, where I set:
    'Value Type' to Game Variable
    'Variable Key' to 'DamageDieSides'
    'Variable Origin' to Selected
    'Selected Key' to 'Value'
    'Value' to 'weapon'

    no dice (literally). My formula always comes up 0's. Just to confirm that the formula was working at all, I change value to just a striaght up number and that number did indeed show up in battle.

    I can also confirm that my combatants are equipped with the short sword in the proper hand.
  • @chud575, glad I could help!

    1. Yes. When you refer to the Selected Key again later, you can access any of the variables that you have defined on that object.

    2. Those settings look right to me. Maybe double-check that your variable names all match up (including case)? Also check that your DamageDieNum and DamageDieSides variables on your weapons are set to type Float. I know, basic stuff, but sometimes these things get missed.

    I took the standard tutorial ORKProject file and added those variables to the Short Sword, and the formula test works for me (didn't try it in battle, but it works in the formula tester in the editor).

    Here are the screen grabs of what I did:

    image

    image

    image

    image

    Does that match what you described above?

  • Interesting - mine also works if you set it up that way. But if you set them as Game Variables, then I cannot access them. @gamingislove any thoughts on this?
  • That's how the system works. The Equipment Variables you've set up in the weapon are bound to the instance of the weapon in the game - i.e. you have to use the selected data feature to select the weapon currently equipped by a combatant (or from the inventory) to access those variables.
    Those variables bound to items, equipment or abilities are only available through selected data and the Selected variable origin.
    Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
  • @gamingislove so the more specific question is: What is the difference between a Value and Game Variables for Equipment Variables?

    for example it appears that Values can be accessed by Events and Formulas. What purpose do GB's serve then?
  • Oh, you're talking about the Value Type setting.

    The Value value type means that you'll directly define what value will be used. The Game Variable value type means that you'll define the key of a game variable that holds the value.

    I.e. for a variable key, you'll usually use the Value value type to directly define the variable key. Using a Game Variable value type would mean that you define the key of a game variable that holds the variable key you want to use.
    Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
  • edited June 2016
    @gamingislove
    Wow... that is... slightly confusing... but i think i get it.

    Can you give me an example of how/why one would use a Equipment Variable->Game Variable? Why would that ever be better than the straightforward value lookup?\

    Also - in @Keldryn's example, he just sets the value by hand for number of dice. Is there no way to set the value of the formula or the value of a local variable equal to the value found in a Selected Data Object?

    This is particularly odd if you can't, because the node "Game Variable Fork" can clearly access Selected Data Value's
    Post edited by chud575 on
  • Example:
    A formula is used to add multiple variables, but gets the variable keys from values stored in other variables. Through that, you can change which variables will be used by storing their keys in the used variables, using a single formula to get different results based on what was set up before using the formula.

    Setting the formula value to the value of a variable (also from selected data) > use the Value step and use the Game Variable value type.
    Setting a variable to the value of another variable > use the Change Game Variables step and use the Game Variable value type in the variable change's value settings.
    Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
Sign In or Register to comment.