Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

Setting a checkbox with workersheets

June 18 (5 years ago)

Edited June 18 (5 years ago)
Koibu
Pro
Marketplace Creator

Seems simple enough, check a box. The backstory is I'm using JSON to import spell details from an outside source into a character sheet so spells don't have to be filled out one at a time. All other input is just text inputs or a textarea, and they all work great. The 3 checkboxes listed below don't work. If they're checked and the JSON is added, they become unchecked regardless of their supposed value.

V<input type="checkbox" name="attr_spellVerbal" value="{{v=1}}" />
S<input type="checkbox" name="attr_spellSomatic" value="{{s=1}}" />
M<input type="checkbox" name="attr_spellMaterial" class="spellMaterial" value="{{m=1}}" />
on('change:repeating_spells1:spellJSON', function(){
    getAttrs(["repeating_spells1_spellJSON"],
        function(v){
            var obj = JSON.parse(v.repeating_spells1_spellJSON);
            setAttrs({
               repeating_spells1_spellName: obj.name,
               repeating_spells1_spellSchool: obj.school,
               repeating_spells1_spellVerbal: obj.verbal,
               repeating_spells1_spellSomatic: obj.somatic,
               repeating_spells1_spellMaterial: obj.material,
               repeating_spells1_spellMat1: obj.materials,
               repeating_spells1_spellRange: obj.range,
               repeating_spells1_spellAoe: obj.aoe,
               repeating_spells1_spellCastingTime: obj.castingTime,
               repeating_spells1_spellDuration: obj.duration,
               repeating_spells1_spellSave: obj.save,
               repeating_spells1_spellDamage: obj.damage,
               repeating_spells1_spellDescription: obj.description,
               repeating_spells1_spellJSON: ''
            });
        });
});

And the JSON

{"name":"Extinguish",
"school":"Abjuration",
"verbal":"1",
"somatic":"1",
"material":"1",
"materials":"A drop of water",
"range":"Self",
"aoe":"50' radius / level",
"castingTime":"1",
"duration":"Instantaneous",
"save":"None",
"damage":"",
"description":"With a snap of their fingers and at least a drop of water, the wizard snuffs out all applicables fires within the AOE. 

At first level, this spell snuffs out all candles, torches, lanterns, small camp fires or other similarly exposed flames. At third level this fire puts out large camp fires and braziers. At fifth level this spell puts out bonfires and small structure fires. At seventh level this spell puts out burning buildings. At ninth level this spell puts out all non magical flames in its area of affect, even a raging forest fire. 

The reverse of this spell, Ignite, will set aflame any small fire yet to be lit. Candles, torches, lanterns, braziers, or small camp fires that are prepared can be ignited. The reverse has no spell component, and will not work to ignite non prepared substances. The thatch of a roof, a small dry bush, or even a pit of oil cannot be lit via this spell."}

I'm at a loss for this simple task. Any help?

June 18 (5 years ago)
Koibu
Pro
Marketplace Creator

Of course after hours of trying to solve this, I figure it out within minutes of asking for help. Here's the stupidly obviously answer:

We don't want to pass "1" to the box to check it, we want to pass it's value which in this case happens to be "{{v=1}}". Little bit of scripting to modify the JSON

            if(obj.verbal == 1){
                obj.verbal = "{{v=1}}";
            }
            if(obj.somatic == 1){
                obj.somatic = "{{s=1}}";
            }
            if(obj.material == 1){
                obj.material = "{{m=1}}";
            }
June 18 (5 years ago)
GiGs
Pro
Sheet Author
API Scripter

well done :)