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

[Help] Custom Sheet : Repeat Field - Button act Script, sourceAttribute is undefined....

February 06 (3 years ago)
TATECK
Pro
Sheet Author

Hello, I need help.

In the repeat section, when a button is pressed, I expect that button to get a repeat value ─ "eventinfo.sourceAttribute
But when I use the actual code, It returns [undefined].

Can you tell me what I did wrong?


HTML Code

<fieldset class="repeating_ab">
    <div class="sheet-ab-item">
        <input type="checkbox" name="attr_ab_flag" class="sheet-check-flag" value="1"/>
        <div class="sheet-ab-control">
            <button class="sheet-dice" type="action" name="act_abillity" value="&{template:Insane} {{subject=@{Ab_Name}}}{{name=@{character_name}}}{{Types=@{Ab_Types}}}{{isMad=[[@{mad}+0)]]}}{{AssignedSkill=@{Ab_spec}}}{{target=[[(@{Ab_target}+0)]]}}{{target_real=[[(@{Ab_target}+0)-(@{all_mod}+0)]]}}{{roll=[[2d6]]}}{{Effect=@{Ab_effect}}}{{mod=[[@{all_mod}+0]]}}"></button>
        </div>
        <div class="sheet-ab-name">
            <input type="text" name="attr_Ab_Name" value="" />
        </div> .....


Script (Sheet work)

on("clicked:abillity clicked:repeating_ab:abillity", (eventInfo) => {
    console.log(eventInfo);
    let templateStr = eventInfo.htmlAttributes.value; ....


Console Result

  1. {sourceAttribute: undefined, sourceType: undefined, triggerName: 'clicked:abillity', htmlAttributes: {…}}
    1. htmlAttributes{class'sheet-dice'type'action'name'act_abillity'value'&{template:Insane} {{subject=@{Ab_Name}}}{{name=@{…}}{{Effect=@{Ab_effect}}}{{mod=[[@{all_mod}+0]]}}'tagName'button'}
    2. sourceAttributeundefined
    3. sourceTypeundefined
    4. triggerName"clicked:abillity"
    5. [[Prototype]]Object




February 06 (3 years ago)
Finderski
Plus
Sheet Author
Compendium Curator

This is just a guess, I’d assume it’s because it’s a button and not an attribute (which are the filed inputs with names that start with attr_). What are you hoping to get out of the sourceAttribute?

February 06 (3 years ago)
TATECK
Pro
Sheet Author

I want to get the id of the repeating section. This is to perform a separate calculation according to the input value of the repeating section.


To use the script of the button action!


startRoll(templateStr, (results) => {
let target = results.results.target.result;
let randomSpec = results.results.randomSpec.result;
let mod = results.results.mod.result * 1;
let result_comp = {};
let spec_name = "";
let spec_cate = 0;
let spec_item = (Math.floor(Math.random() * 6) + 1) + (Math.floor(Math.random() * 6) + 1); ....

파인더스키 said:

이것은 단지 추측일 뿐이며 속성이 아니라 버튼이기 때문이라고 가정합니다(이름이 attr_로 시작하는 입력된 입력). sourceAttribute에서 무엇을 얻고자 합니까?




February 06 (3 years ago)
TATECK
Pro
Sheet Author

I know the same code for the function I want. This code works fine. (The form of HTML code is also the same.)

But my code is not working. I don't know why.

This is the working code.

on('clicked:roll clicked:repeating_acitems:roll', (event) => {
let rollPart = event.htmlAttributes.value;
let assignedSkill;
if (event.sourceAttribute && event.sourceAttribute.startsWith("repeating_acitems")) {
let trigger = event.triggerName.slice(8);
let prefix = trigger.split('_').slice(0,3).join('_') + '_';
rollPart = rollPart.replaceAll('prefix-', `${prefix}`);
assignedSkill = prefix+'Magic_Assigned_Skill';
} else {
const match = rollPart.match(/Magic_\d\d_Name/);
if (match) {
assignedSkill = match[0].replace('Name','Assigned_Skill');
}
}

getAttrs(["character_name",assignedSkill], function(values) {




February 06 (3 years ago)
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator

Hi R,

For action buttons, the triggerName is the best way to get the details of the roll. I recommend not relying on the htmlAttributes property as it is empty when the button is called from chat. To get the full information about the roll, I use a function from my K-Scaffold:

const parseTriggerName = function(string){
  let match = string.replace(/^clicked:/,'').match(/(?:(repeating_[^_]+)_([^_]+)_)?(.+)/);
  match.shift();
  return match;
};
on("clicked:abillity clicked:repeating_ab:abillity", (eventInfo) => {//Having a repeating and non repeating version of the button in your listener may cause doubling of events for the repeating button. Attribute listeners definitely would double in this situation, but I am not sure if the ability listeners work the same way in that regard.
  console.log(eventInfo);
  let [section,rowID,field] = parseTriggerName(eventInfo.triggerName);
  /*
    For a repeating action button named repeating_equipment_-LKJhpoi98;lj_roll:
      section = 'repeating_equipment'
      rowID = '-LKJhpoi98;lj'
      field = 'roll'
    For a non repeating button named roll:
      section = undefined
      rowID = undefined
      field = 'roll'
  */
  let templateStr = eventInfo.htmlAttributes.value;//I really recommend storing the macro expression in the JS itself and getting it based on the roll button name so that your action buttons can be called from chat.
});

And, a side note, I think you might want the actual name of the button to be "ability" instead of "abillity"?

February 07 (3 years ago)
TATECK
Pro
Sheet Author

Thanks for the advice. It has been modified with ability =>abillity   However, it did not solve the root cause. TT

The trigger for the button in the repeat section is not working.

In the repeat section, when the button is clicked

clicked:repeating_ab:abillity 

Failed to call this event.


on("clicked:repeating_ab:abillity", (eventInfo) => {...

Even if the non-repeated listener is excluded, this event is not called. <ㅇ>..!!!





Scott C. said:

Hi R,

For action buttons, the triggerName is the best way to get the details of the roll. I recommend not relying on the htmlAttributes property as it is empty when the button is called from chat. To get the full information about the roll, I use a function from my K-Scaffold:

const parseTriggerName = function(string){
  let match = string.replace(/^clicked:/,'').match(/(?:(repeating_[^_]+)_([^_]+)_)?(.+)/);
  match.shift();
  return match;
};
on("clicked:abillity clicked:repeating_ab:abillity", (eventInfo) => {//Having a repeating and non repeating version of the button in your listener may cause doubling of events for the repeating button. Attribute listeners definitely would double in this situation, but I am not sure if the ability listeners work the same way in that regard.
  console.log(eventInfo);
  let [section,rowID,field] = parseTriggerName(eventInfo.triggerName);
  /*
    For a repeating action button named repeating_equipment_-LKJhpoi98;lj_roll:
      section = 'repeating_equipment'
      rowID = '-LKJhpoi98;lj'
      field = 'roll'
    For a non repeating button named roll:
      section = undefined
      rowID = undefined
      field = 'roll'
  */
  let templateStr = eventInfo.htmlAttributes.value;//I really recommend storing the macro expression in the JS itself and getting it based on the roll button name so that your action buttons can be called from chat.
});

And, a side note, I think you might want the actual name of the button to be "ability" instead of "abillity"?




February 07 (3 years ago)
TATECK
Pro
Sheet Author

I tested by deleting the code line by line to solve this problem.
And I made a surprising discovery.

God, I can't believe it. Inside the repeating section, The problem was the div that wraps the whole thing right below it.

<fieldset class="repeating_ab">
    <div class="sheet-ab-item">


When I peeled off the enclosing <div class="sheet-ab-item"> , it was confirmed that it was working normally.

Why the hell was this a problem? I don't know...
I'm really, really curious. Why is it applied as a regular event rather than a <repeating_> event listener when I wrap a div once?

Anyway, it worked out safely. Thanks to everyone who helped!


February 07 (3 years ago)
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator

Ah! Ok, so this is a bug due to how action buttons are associated with a repeating row.. I am guessing that you had applied a position property to that div. Having a position property applied to one of the containers of the button in the repeating row causes the button to not be recognized.

February 07 (3 years ago)
TATECK
Pro
Sheet Author

The position property was the problem!!! The question has been resolved. Until the bug is fixed, I'll be careful writing it.

Thank you so much for your help!!!

February 07 (3 years ago)
Andreas J.
Forum Champion
Sheet Author
Translator

Added to the list: https://wiki.roll20.net/Character_Sheet_Development/Bugs_%26_Quirks#Repeating_Sections