Help JavaScript please

So this is literally the first time I've ever tried to code JavaScript so be gentle with your responses, please :smile:

I'm trying to get CSD to roll some dice for some values on my sheet. So I wrote up a little JavaScript that looks like this to try & roll a d5:

function HitDice ()
         RollDice ( 1, 5, 0)

And I put this as the Field Source (the field is named "HP"):

js.HitDice (HP.Value)

When I open the Sheet up in the viewer, I get the folowing error:

Native Expression Error: HP
Error: Invalid Expression
Expression: js.HitDice

So what am I missing? Or is there an easier way to have fields roll dice values that I don't quite understand from the Help file?

Thanks in advance!

Nightblade ->--


  • For the field source, I believe it should be set like:


    (ie, a colon, not a period)

    And then your function, you need to return the value. So something like:

    function HitDice( d)
       return RollDice ( 1, d, 0)

    Also, since you're using HP.Value, you need to have a field called HP on your sheet that has a value in it (like '8')

Leave a Comment