Question about javascript in NBOS character sheet designer

Hello, I have a pretty specific thing I'm trying to set up on a character sheet using javascript.

I have locational damage in my system, and what I want to do is set it up so there's a part of the sheet that says
"I am taking [amount of damage] [damage type] damage to my [bodypart] : [button that deals damage]"
where [amount of damage] is a text field, and [damage type] plus [bodypart] are both text fields using lists.

So then the player could, for example, do:
"I am taking 11 slashing damage to my right arm", click the button, and then that bodypart would be modified in the correct way.

So, let's say the [bodypart] bit is a a text edit field using a list. How can I make what the list is selecting choose what text field the damage number is applied to?

Comments

  • There are of course several ways to do this, but one way would be calling a script function from a button with the source like
    js:ApplyDamage()
    and in the script tab define the function something like this

    function ApplyDamage()
    {
      switch(lstBodyparts.Text)
      {
        case "Head":
          txtHead.Text=txtHead.Value - txtDamage.Value;
          break;
        case "Torso":
          txtTorso.Text=txtTorso.Value - txtDamage.Value;
          break;
        case "Left arm":
          txtLeftArm.Text = txtLeftArm.Value - txtDamage.Value;
          break;
        // and so on
        default:
          // not found
          break;  
      }
    }
    

Leave a Comment