edited December 2021 in ORK Support
I'm trying to create a formula that emulates a dice roll and I'm struggling a bit. Formula's are really powerful, but I'm not a coder so some of the options don't make full sense to me yet.

The idea:

A status value is the number of d10's being rolled. I.E Strength of 4 means 4d10. The value of each dice rolled is added together. That tally is then compared to the targets defense (a separate formula), and if higher then roll is successful.

Additionally, rolling a 1 gives a Negative Status Effect, and a 10 gives a Positive Status Effect. These effects statck and can be used to fuel abilities or hinder.

Currently my formula idea is:

image

I know change Variables is a key part of it, but I'm still a bit fuzzy on how to use it properly.

I just feel like I'm going about this the hard/wrong way.
Post edited by Solkyoshiro on
Currently making: Real-Time Diablo-like ARPG
  • edited December 2021
    Trying this arrangement currently. One thing I'm trying to figure out is how to add on a Status Effect as part of a formula, or can you not?

    https://imgur.com/a/889zdQ0
    Post edited by Solkyoshiro on
    Currently making: Real-Time Diablo-like ARPG
  • edited December 2021
    Okay, I believe I understand what you're asking. You should definitely be using a variable for this formula, specifically, a Local Variable. You can think of variables as folders that hold information. Instead of accessing the information directly, you access the variable and it tells you the information inside it. For example, a variable called "Name" can hold "string" of "Bob". You can use "Name" instead of "Bob" for dialogue, and if you ever wanted to change Bob's name, you just have to change the variable "Name" and it will be updated every where the variable(global) is used. In this case, we will use a local variable since we only need this value in this schematic. This is how you would set it up.

    -Start a Loop with a max count based on your d10 status value. The variable counter can be named what ever you want since it won't be needed here.
    -Use Change Variable, name it "Random Value"(or what ever you want) and set it's Variable Origin to Local. Next, set Type to Int, Operator to Set, and Float Value to Random. The Random values will be 1-10.
    -Next create a Variable Fork. The variable key will be "Random Value"(or what ever you named it) Make sure it's set to Local as well.
    -Add a Variable Condition. Set it's type to Int. Set the Check Type to Range Inclusive. The values should be 2 and 9.
    -Create two more Variable Conditions, both int and both with a Check Type of "Is Equal".
    -Set them to 1 and 10.
    -If the "Random Value" Variable is between 2 and 9, you simple use Value to Add the Int Variable "Random Value" to the over all Formula Value.
    -If it lands on 1 or 10 then things get a bit tricky. You can't set statue effect in formulas, but you can "listen" for global variables changes and auto set status effects on users or targets. Or you can move the d10 "Random Value" logic into an ability and only do the Atk/Def check in a formula. This will allow you to set status effects if you get a 1 or 10 roll.

    It seems your biggest problem is being unfamiliar with variables. You should look up some tutorials on variables to make sure you understand them well as they are the basis of working with Unity and Ork. Here is my set up for visual reference.

    image
    Post edited by Dre788 on
  • Thanks @Dre788 for breaking it down. I understand variables as a concept, but I'm still very new at seeing the best way to use them, especially in a node circumstance.

    But you are right, variables is my weakest point so far. I've gone through various Unity tutorials and read through Ork, and while they are good at showing how to use them in that circumstance, I always find myself at a roadblock when implementing my own unique things.

    Gil as well mentioned Variable Forks. I'm going to take what you both said and see what I come up with.
    Currently making: Real-Time Diablo-like ARPG
  • If you want to add a random value between 1 and 10 (or between any values), use a Value node with value type Value > Random. You can here define the min and max value, and if you need int values, use the Math Function setting to e.g. Round the value (or Ceil/Floor it).

    The Value node will use it's value to change the formula's result, e.g. Add operator to add it to the current result. So, if you want to have 4 d10 rolls, just copy the node to have 4 of them or use a Loop node to use it 4 times.

    If you want to use such a formula for a hit chance of an ability/item, you can e.g. do your 4 d10 rolls, subtract the target defence formula and check the formula value - Check Value node with Value > Current Value type, e.g. checking for greater than 0. After the check, you should use a Value node with Set operator to set the formula result to either 100 or 0 (for 100% or 0% chance).
    You could also change the chance check values in the game settings and use some other values than 0-100.

    The variable fork I mentioned was for a different situation, where you want to apply different status effects depending on a roll. In such a case, you'd use a formula (or if it's just for a single roll, you can also use a Change Variables node directly to set a random value like in the formula) to store the value into a variable and check the variable, doing different things based on it.
    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 for the help @gamingislove, though this part of what you said confused me.
    After the check, you should use a Value node with Set operator to set the formula result to either 100 or 0 (for 100% or 0% chance).
    You could also change the chance check values in the game settings and use some other values than 0-100.
    What would be the purpose of the 100 or 0 in your example?
    Currently making: Real-Time Diablo-like ARPG
  • edited December 2021
    That's an example for using a dice roll formula for hit chance (or critical chance, or any chance check).

    Chances check the used value (e.g. the result of the formula) against a random value between 0 and 100 (you can change the chance values in Game > Game Settings).

    So, if your dice roll formula is used for a chance check like hit chance, it needs to return a value compatible with the chance range - if the formula itself already checks if it's a success, you'd set the result to 100 or 0 based on that. 100 being a hit/success, 0 being a miss/fail.
    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!
  • edited January 2022
    So I've been working on this formula at I'm still having issues @gamingislove.

    image

    This is what I've currently constructed and it doesn't seem to be working right. I tried to do close to what you mentioned but I had to make a number of adjustments.

    I can't just repeat a random value because it's meant to be a variable. It's why I say d10, I want the number of dice rolls based on a status value. Let me be more specific about my formula and what I'm trying to accomplish.

    A Status Value determines how many "dice" are rolled. Depending on the number that's rolled, they gain a buff or debuff with 10 and 1 being the worse. The values are added together at the end and compared to either defense if it's a living entity or a static difficulty number based on the difficulty of the action.

    So the equation is

    (d10 + x) - Target's Defense > 0 = Success

    1= Super Negative Effect
    2-3 = Negative Effect
    4-7 = No Effect
    8-9 = Positive Effect
    10 = Super Positive Effect

    d would be a Status Value of the User.
    x would be attack modifiers and such from abilities/gear etc.
    Target's Defense would be a Status Value that is a combined stat using a formula.

    And if the value is greater than 0 then they hit.

    The effects would be something that lets me trigger Status Effects, like setting a variable.

    I truly just need to work out the core d10 part with the effect flags, then I can use that as a core formula for my system.

    Post edited by Solkyoshiro on
    Currently making: Real-Time Diablo-like ARPG
  • Dice rolls based on status value can use the Loop node with Max Count being the status value (you can use a status value directly as a value: Combatant > Status Value in the max count field).

    Do what you need in the loop (e.g. Value node with random 1-10 value) and what you need to do after the loop finished.

    However, a formula isn't used to change the status of a combatant (e.g. add status effects) - a formula is only used for calculating values, which are used to change things.

    E.g. if you want to change a status effect based on the formula result in a schematic, use a Change Variables node in the schematic that uses the formula to set a variable (int or float) and do your value check and status value changes on the variable.
    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 January 2022
    That's basically what I did with my formula above, right @gamingislove?

    Edit:

    Maybe I should detail how my formula is currently set up.

    1.) Formula start node
    2.) Loop with Max Count set to Status Value (Speed stat in this example). A temp variable key (status_Score), with the origin set to Local.
    3.) Change Variables Node with a local float variable key (d10Roll) set to a random Float Value between 1 and 10.
    4.) Variable Fork for variable key d10roll with 4 different Range inclusive conditions. 1, 2-3, 4-7, 8-9, and 10.
    5.) 1 goes to a Change Variable node where it adds a float value of 1 to a global variable Crisis. 2-4 goes to a Change Variable with global variable key consquence, and so on.
    6.) Value node where you add the variable key d10roll to formula.
    7.) Connects back to loop in Step 2.
    8.) End.

    I think I may not be handling the loop or variable forks correctly? It's hard to test this kind of formula using the Test Formula option.
    Post edited by Solkyoshiro on
    Currently making: Real-Time Diablo-like ARPG
  • On closer inspection, probably, yes - though it's a bit hard to tell at first glance due to the renamed nodes :)

    If I understand correctly, you want to do different stuff based on each roll, correct?
    In that case, instead of handling all this in a formula, handle it in the schematic.
    - schematic also has Loop node where you can loop based on the status value
    - you can directly set a variable to a random value without using a formula
    - and check the variable > do stuff based on that

    Otherwise, I think I'll need some more infos in how/where the formula is used. As said, formulas are used to calculate a value, not handle status changes (or similar things).
    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 January 2022
    Haha I figured I needed to explain it more in-depth, I edited my post above @gamingislove.
    1.) Formula start node
    2.) Loop with Max Count set to Status Value (Speed stat in this example). A temp variable key (status_Score), with the origin set to Local.
    3.) Change Variables Node with a local float variable key (d10Roll) set to a random Float Value between 1 and 10.
    4.) Variable Fork for variable key d10roll with 4 different Range inclusive conditions. 1, 2-3, 4-7, 8-9, and 10.
    5.) 1 goes to a Change Variable node where it adds a float value of 1 to a global variable Crisis. 2-4 goes to a Change Variable with global variable key crisis, and so on.
    6.) Value node where you add the variable key d10roll to formula.
    7.) Connects back to loop in Step 2.
    8.) End.
    Then I have a Status Bonus template set up with Auto Status effects where the condition is if a variable is valid, exists and is above 0.
    Post edited by Solkyoshiro on
    Currently making: Real-Time Diablo-like ARPG
  • Based on that description, the formula should be correct - however, where is the formula actually used?

    The status bonus template, where is that used?
    Also, since you're using global variables, they'd affect all combatants who have that status bonus template in any way.
    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 January 2022
    Hmm I want the variables to be stored and checked on each combatant separately.

    Would a local variable do that? Or is this when I use selected data?

    And I had the template set as a default for combatants in the general settings.
    Post edited by Solkyoshiro on
    Currently making: Real-Time Diablo-like ARPG
  • In that case, use Object variable origin instead of Global, using the combatant as the game object (e.g. user or target of the formula).

    Still - where is the formula used?
    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!
  • Excellent, I was on the right track. I was actually looking at Object variable origins.

    The formula is used in a status value as the formula for Combined Value. Though after toying with it all day I see what you mean about schematics. I just have to think about formulas and schematics a bit differently I suppose.

    Currently making: Real-Time Diablo-like ARPG
Sign In or Register to comment.