Hi there,

So I'm writing a formula. In that formula i throw a couple dice, and store the value of each roll into a local variable. How do i call the formula from an event, and access the variables?
  • You can't access local variables outside of the scope in which they are declared -- in this case, the formula.

    You could try setting object variables in the formula (on either the User or Target) and then accessing those object variables from the event. You just need to make sure that you have (local) object variables enabled on the combatants or the Object Variables component added to the object.
  • You can e.g. use the Formula To Variable step to call a formula in an event. Events and formulas share the local variables, i.e. if you change local variables in formulas, those changes will also be present in the event that called the formula.
    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!
  • okay great - thats actually what i was hoping to hear. That means the formula can store all the dice rolls, and then the event can access them later after it calls the formula, which is what i wanted.
  • I stand corrected. :-)
  • edited June 2016
    Okay next question:
    Let's say I'm calling the formula from script, and thus i want the formula to store values in my script.

    I have no troubles calling the formula using this code:
    int die1; // store die roll here
    int value = (int)ORK.Formulas.Get(formulaID).Calculate(new FormulaCall(0, player, player));
    In the formula, after rolling die1, I call 'Store Formula Value'
    Variable Origin: Object
    Status Origin: User
    Variable Key Value Type: Value
    Value: die1

    But this doesnt work. I assumed Status Origin should be User, thinking that means the object that called the formula, not a pre-stored combatant.

    How should I approach this?
    Post edited by chud575 on
  • Does your user (player in your case) use object variables? I.e. either enablre Use Object Variables in the combatant's settings, or add an object variable component to the game object (or prefab) of the combatant.
    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.