• 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

Why is the same skill showing up three times in a foreach loop?

EightBitz

Well-known member
First of all, scratch my previous question about the labeltext script. I'm doing that whole thing a different way, which I think will still work out the way I want it, but I'm having another odd issue now.

I have the following portal:
Code:
<portal
   id="skill"
   style="outNormal">
   <output_label>
      <labeltext><![CDATA[
         var attrname as string
         var skillname as string
         var linkname as string
         var debugstr as string
         
         attrname = field[name].text
         foreach pick in hero from Skill where "component.Skill & !Helper.Maximum & !Hide.Skill"
            skillname = eachpick.field[name].text
            linkname = eachpick.linkage[attribute].field[name].text
            if (compare(attrname,linkname) = 0) then
               debugstr = "attrname: " & attrname & ", skillname: " & sklname & ", linkname: " & linkname
               debug debugstr
               done
               endif
            nexteach
         ]]></labeltext>
      </output_label>
   </portal>

The debug output for that portal is:
Code:
**********  Start Evaluation Cycle  **********

attrname: Agility, sklname: Movement, linkname: Agility
attrname: Agility, sklname: Movement, linkname: Agility
attrname: Agility, sklname: Movement, linkname: Agility
attrname: Strength, sklname: Prowess, linkname: Strength
attrname: Stamina, sklname: Close Quarters Combat, linkname: Stamina
attrname: Focus, sklname: Research, linkname: Focus
attrname: Personality, sklname: Communication, linkname: Personality
attrname: Willpower, sklname: Interview, linkname: Willpower
attrname: Dexterity, sklname: Fieldcraft, linkname: Dexterity
attrname: Perception, sklname: Investigation, linkname: Perception
attrname: Reflexes, sklname: Ranged Weapons, linkname: Reflexes

Notice that the movement skill, which is linked to the Agility attribute is showing up three times instead of just once. I am stumped again.
 
Just covering the obvious, have you checked the debug output to be sure that you don't have Agility or Movement added multiple times to your hero?
 
Yep. And they're both set as unique.
I would add debug logic to confirm the thingid so you can be sure what your looking at.

Code:
debug eachpick.idstring

Honestly it looks like you have multiple Picks on the Hero. Once you get the Thing ID you can confirm if they are really the same Pick or different.
 
I would add debug logic to confirm the thingid so you can be sure what your looking at.

Code:
debug eachpick.idstring

Honestly it looks like you have multiple Picks on the Hero. Once you get the Thing ID you can confirm if they are really the same Pick or different.

It's the same idstring all three times.
That is the only thing with a name of "Movement"
Movement is defined as unique.
All the skills are bootstrapped in bootstrap.1st, and since they're all unique, nothing is user selectable, so no skill can be added multiple times.
 
I would add debug logic to confirm the thingid so you can be sure what your looking at.

Code:
debug eachpick.idstring

Honestly it looks like you have multiple Picks on the Hero. Once you get the Thing ID you can confirm if they are really the same Pick or different.

Also, on the final output, it's only listed once. If it was actually duplicate picks on the hero, it would be listed multiple times, no?

EDIT: No, scratch that. With this logic, it would only be listed once. But in the UI, it's listed on the skills table only once, and THAT should be an indication that it's only picked once.
 
Just to see what would happen, I removed "isunique='yes'" from the Movement skill, and I got an error that the linked trait must be unique. So I put it back, then removed it from Agility. I get an error that the compset requires it to be unique.

So, not only are both unique, but one is required to be unique by its compset, and the other is required to be unique by virtue of having a linkage.

EDIT: Actually, I misread one of the error messages. For "Movement", it's the compset as well. For both skills and attributes, their compsets require them to be unique.
 
Last edited:
Try adding a

Code:
debug "starting script"

at the very beginning, so that you can tell if the script has re-started - visual elements can end up being generated several times.
 
Try adding a

Code:
debug "starting script"

at the very beginning, so that you can tell if the script has re-started - visual elements can end up being generated several times.

I see it starting three times for Agility, but once for everything else.

It's not impeding any function. But it is strange.

Sorry, I should say three times for Movement, which is linked to Agility.
 
Yeah, visual elements can get regenerated several times. Does that happen to be the first item in the table - that could mean a pass specifically to get the height of the first element, which will then be used to lay out the rest of the table.

Is it an option to build all this text in a component field, which the visual element can just look up? That saves the foreach from having to run so many times.
 
Yeah, visual elements can get regenerated several times. Does that happen to be the first item in the table - that could mean a pass specifically to get the height of the first element, which will then be used to lay out the rest of the table.

Is it an option to build all this text in a component field, which the visual element can just look up? That saves the foreach from having to run so many times.

As to the first part of your comment, what I'm getting from it is that the script is being called for reasons which might not be obvious to me, so this isn't completely unexpected.

As to the second part of your comment ... maybe, but that wouldn't solve my whole problem, and I'm not sure that would be the best solution. There are attributes, skills, and specializations. I'm emulating the official character sheet in putting all things related to a given attribute on the same line. So three columns:

Attributes | Skills | Specializations

I have a template that includes:
- One portal for attributes that looks up each attribute.
- One portal for skills that looks up each skill linked to that attribute.
- One portal for specializations that looks up each skill linked to that attribute, then for each skill, it looks up each specialization linked to that skill.

Wherever I determine these output fields, I'd have to have equivalent loops somewhere. The loops that will run the least are the ones for printing character sheets.
 
Hero Lab now has tests to determine if it needs to regenerate the text of a field between evaluations, in order to speed up the time required to recalculate everything on a character, so if all of that is calculated in component scripts and stored in fields, then it will probably not need to be recalculated for that same character during a single period that the user has HL open, but if the calculations are in the visual elements, they're recalculated every time the user looks at that tab, and every time they change something while that tab is open.
 
Hero Lab now has tests to determine if it needs to regenerate the text of a field between evaluations, in order to speed up the time required to recalculate everything on a character, so if all of that is calculated in component scripts and stored in fields, then it will probably not need to be recalculated for that same character during a single period that the user has HL open, but if the calculations are in the visual elements, they're recalculated every time the user looks at that tab, and every time they change something while that tab is open.

This is just for the character sheet. It's not on the tabs in the UI. Those are all self-contained. And during character creation, some of these fields will be changing quite a bit. Adding points to skills, then maybe changing your mind and taking them away to put them somewhere else; or adding specialties and arranging points between them, then maybe changing your mind and removing them or changing points between them, etc.

I still feel like there will be more recalculation during character creation than if I just left these scripts on the character sheet.
 
Back
Top