Lone Wolf Development Forums

Lone Wolf Development Forums (http://forums.wolflair.com/index.php)
-   HL - Authoring Kit (http://forums.wolflair.com/forumdisplay.php?f=58)
-   -   Retrieving the name of a parent on a pick (http://forums.wolflair.com/showthread.php?t=63163)

Duggan September 8th, 2019 08:14 AM

Retrieving the name of a parent on a pick
 
This is probably something super-obvious that I'm just not getting at the moment, but I have Components for certain skill bonuses in my system like the following:
Code:

<!-- SkillBonus component -->
<component
  id="SkillBonus"
  name="Starting Skill Bonus"
  autocompset="no"
  panellink="basics">
   
  <field
    id="skbName"
    name="Name"
    type="user"
    maxlength="20"/>
 
  </component>

They exist within a compset that is then used to used for specific bonus types like the following:
Code:

<thing
  id="fRPlusSk"
  name="Skill Bonus"
  compset="cmpsetSB"
  description="Gives a bonus to the selected skill.">
  <fieldval field="usrCandid1" value="component.Skill"/>
  <tag group="Hide" tag="Special"/>
  <eval index="1" phase="PreTraits" priority="4900">
    <before name="Calc trtFinal"/><![CDATA[
    var bonus as number
    var penalty as number
    bonus = tagvalue[Bonus.?]
    penalty = tagvalue[Penalty.?]
    if (bonus = 0) then
      if (penalty = 0) then
        bonus = 2
      else
        bonus = penalty
      endif
    endif
   
    if (bonus > 0) then
      field[livename].text = "+" & bonus & " " & livename
    else
      field[livename].text = bonus & " " & livename
    endif
   
    ~build the candidate expression out of our Skill and Skills tags
    var skills as string
    skills = tagids[Skill.?, " | "]
    var skilltypes as string
    skilltypes = tagids[Skills.?, " | "]

    var combined as string
    if (tagis[Skills.?] <> 0) then
      if (tagis[Skill.?] <> 0) then
        combined = skills & " | " & skilltypes
      else
        combined = skilltypes
      endif
    else
      combined = skills
    endif
   
    ~ debug combined & ", " & empty(combined)
    if (empty(combined) = 0) then
      field[usrCandid1].text &= " & (" & combined & ")"
    endif
   
    perform field[usrChosen1].chosen.field[trtBG].modify[+,bonus,field[skbName].text]
    ]]></eval>
  </thing>

Those bonus things are bootstrapped into backgrounds like the following. I would like to only use skbName if specified and, if not, to use the thing name it's bootstrapped to:

Code:

<thing id="bckCrime" name="Crime Lord" description="You probably didn’t get your lawless hands very dirty, but you definitely know some people who did — and they did it on your orders.\n\n{b}Bonus Skill Ranks:{/b} +2 Deceive, +2 Economics {i}or{/i} History, +2 Inspire {i}or{/i} Negotiate" compset="Bckgrnd" uniqueness="unique">

  <bootstrap thing="fRPlusSk2">
    <autotag group="Skill" tag="skDeceive"/>
    </bootstrap>
 
  <bootstrap thing="fRPlusSk">
    <autotag group="Skill" tag="skEcon"/>
    <autotag group="Skill" tag="skHistory"/>
    <autotag group="explicit" tag="1"/>
    </bootstrap>
  <bootstrap thing="fRPlusSk">
    <autotag group="Skill" tag="skInspire"/>
    <autotag group="Skill" tag="skNegot"/>
    <autotag group="explicit" tag="2"/>
    </bootstrap>
  </thing>

I'd like the modification line to pull from a field value on SkillBonus since I use SkillBonus's compset in a few different contexts and I'd prefer them to all be using the same field instead of duplicating the logic.

Duggan September 8th, 2019 09:42 AM

Ah, I think "root" is what I want.

Duggan September 8th, 2019 04:15 PM

Hmm... and either I misunderstand something about field histories or I implemented this incorrectly. My current SkillBonus:
Code:

<!-- SkillBonus component -->
<component
  id="SkillBonus"
  name="Starting Skill Bonus"
  autocompset="no"
  panellink="basics">
 
  <field
    id="skbNamCst"
    name="Custom Name"
    type="user"
    maxlength="20"/>
   
  <field
    id="skbName"
    name="Name"
    type="static"
    maxlength="20"
    maxfinal="20">
    <finalize><![CDATA[
      if (this.field[skbNamCst].isempty = 0) then
        @text = field[skbNamCst].text
      elseif (this.isroot <> 0) then
        @text = this.root.field[name].text
      else
        @text = this.field[name].text
      endif
      ]]></finalize>
    </field>

  </component>

My code for updating the skill bonus is:
Code:

perform field[usrChosen1].chosen.field[trtBG].modify[+,bonus,field[skbName].text]
And yet, when I look at my mouseover, defined as follows:
Code:

<mouseinfo mousepos="middle+above"><![CDATA[
    @text = field[trtBG].history[", "] & "{BR}" & field[trtUser].value & " spent in creation"
    ]]></mouseinfo>

I see something like "+2 Skill Bonus: Dodge, +1 Skill Bonus: Dodge" instead of "+2 Crime Lord, +1 Ob'enn" like I might expect from the source of the skill bonuses.

Duggan September 8th, 2019 05:11 PM

And, with further debug statements, it seems that I'm not getting the field I expect. field[skbName] is empty at the time of evaluation.

ShadowChemosh September 8th, 2019 06:53 PM

I am pretty sure that finalize script is meant to set a value for the UI. Meaning its done very late in processing. For example from Pathfinder the abDC field would finalize with a script that sets a value of "DC X" where X is the value of abDC.

I think you want to not use a finalize script and instead use a component script that runs semi early so that skbName gets a name. This way you are 100% in control of when the script executes. :)

Mathias September 8th, 2019 09:03 PM

Also, I would not use a static field for something you intend to use a finalize script for. I'm not certain about it, but that seems likely to run into HL's speed optimizations - where if a field's doesn't change, HL doesn't recalculate things based on it, which may include the finalize script - see the acHPSumm field in actor.str in the skeleton files for an example of how a field that's only used for its finalize value has been set up - as a numerical derived field that stores a value that's designed to change if any of the elements that go into it change, and then with the finalize script to handle the text.

Mathias September 8th, 2019 09:04 PM

But, in order to use the field in a history, you'll need to change it to be a derived string field (skip the finalize), and make sure to set it before the script that's trying to use it to build the text for the history entry.

Duggan November 19th, 2019 01:54 AM

Minor follow-up, that's exactly what I needed to do, was to move it into an eval and do it earlier.

Code:

<!-- SkillBonus component -->
<component
  id="SkillBonus"
  name="Starting Skill Bonus"
  autocompset="no"
  panellink="basics">
 
  <field
    id="skbNamCst"
    name="Custom Name"
    type="user"
    maxlength="20"/>
   
  <field
    id="skbName"
    name="Name"
    type="derived"
    maxlength="20">
    </field>
 
  <eval index="1" phase="Initialize" priority="3005"><![CDATA[
    if (this.field[skbNamCst].isempty = 0) then
      field[skbName].text = field[skbNamCst].text
    elseif (this.isroot <> 0) then
      field[skbName].text = this.root.field[name].text
    else
      field[skbName].text = this.field[name].text
    endif
    ]]></eval>
  </component>



All times are GMT -8. The time now is 01:35 AM.

Powered by vBulletin® - Copyright ©2000 - 2024, vBulletin Solutions, Inc.
wolflair.com copyright ©1998-2016 Lone Wolf Development, Inc. View our Privacy Policy here.