• Please note: In an effort to ensure that all of our users feel welcome on our forums, we’ve updated our forum rules. You can review the updated rules here: http://forums.wolflair.com/showthread.php?t=5528.

    If a fellow Community member is not following the forum rules, please report the post by clicking the Report button (the red yield sign on the left) located on every post. This will notify the moderators directly. If you have any questions about these new rules, please contact support@wolflair.com.

    - The Lone Wolf Development Team

Using an array to set attributes?

TCArknight

Well-known member
Howdy!

in the system I'm playing around with there are 10 attributes which can be generated randomly. For Random generation, I am storing the initial/base value in an array on the hero. Each attribute pulls the array value into the BaseValue field. Once those are set, then the values of two attributes can be swapped. Swapping is done through two choosers, one for the "from:"and one for the "to:". When a button is clicked, the two values in the array change should change.

The Base Value field of the attributes change, but the FinalValues never recalculate.

Code:
(Procedure to load the array to the various attributes)
  <procedure id="RecalcBaseScores" scripttype="none"><![CDATA[
    ~declare variables that are used to communicate with our caller
    var score as number
    var i as number
    
    i = 0
    
    foreach pick in hero from Attribute
      eachpick.field[trtBaseValue].value = herofield[acRandomAbils].arrayvalue[i]
      i += 1
      nexteach

    ]]></procedure>

(Eval Script on the Attribute Component)     
    <!-- Calculate the final value from the three distinct pieces -->     
    <eval index="1" phase="Traits" priority="3000" name="Calc trtFinal"><![CDATA[
      if (hero.tagis[source.srcAbilityRandom] <> 0) then
        Call RecalcBaseScores
        endif
        
      field[trtFinal].value = field[trtBaseValue].value + field[trtUser].value + field[trtBonus].value + field[trtGear].value + field[trtInPlay].value
      ]]></eval>

Is there a secret to getting the trtFinal field to recalculate?
 
So this one procedure will get called for every attribute, so it'll be run 10 times, and each time it's run, it overwrites the values on all the attributes, even the ones that have already calculated their trtFinal? I'd pull out the procedure call, and move it to a script on the hero, and move the timing to earlier than Calc trtFinal.

Also, create a sort order for this foreach to use - you don't want to have any uncertainty in the order in which the values are applied.

This is a procedure for an eval script, but it has scripttype="none" not scripttype="eval".
 
Thank you. I've made some changes based on that. I tried putting the script to call the procedure on the actor at Traits/1000 (trtFinal is at Traits/3000 in this case) but on the hero it never seems to get called.

I know there is a change script available for choosers and menus. Is there something similar for arrays or fields?
 
Not getting called on the hero sounds like a major bug. Could you give me more information there?

No, there isn't a change script for fields.
 
It's strange... it doesn't trigger off the hero. When I moved it to a trigger script off the button I have to trigger the swap, then it ran and showed the proper new values but not on the trtFinal values. :(

Code:
ACTOR:
    <eval index="6" phase="Traits" priority="1000" ><![CDATA[
      Call RecalcBaseScores
        
      notify "End Swap"
      ]]></eval>

PROC:
  <procedure id="RecalcBaseScores" scripttype="eval"><![CDATA[
    ~declare variables that are used to communicate with our caller
    var score as number
    var i as number
    
    i = 0
    
    foreach pick in hero from Attribute sortas explicit
      debug "RECALCING " & eachpick.field[name].text & 
      debug "  Before: " & eachpick.field[trtBaseValue].value
      eachpick.field[trtBaseValue].value = herofield[acRandomAbils].arrayvalue[i]
      debug "  Now: " & eachpick.field[trtBaseValue].value
      i += 1
      nexteach
      
    ]]></procedure>
 
I think I have it. :)

I removed the eval script from the actor completely and added the Recalc procedure to a :trigger: type and it to only be triggered when the Swap button is triggered. One additional thing I did was make the herofield[acRandomAbils] into full persistence. Now, it swaps with no issue.
 
Back
Top