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

How to expand code into inline rolling code manually?

Hi! Is there any way to expand code like %{-Kt-X-OGE_Ib0UcH-KR_|repeating_npcaction_-Kt-X-fj3H6XL4VdJ-Jv_npc_action} into @{Veteran|wtype}&{template:npcaction} {{attack=1}} {{damage=1}} {{dmg1flag=1}} @{Veteran|npc_name_flag} {{rname=Longsword (One-Handed)}} {{r1=[[@{Veteran|d20}+(5+0)]]}} @{Veteran|rtype}+(5+0)]]}} {{dmg1=[[1d8 + 3+0]]}} {{dmg1type=slashing}} {{dmg2=[[+0]]}} {{dmg2type=}} {{crit1=[[1d8+0]]}} {{crit2=[[+0]]}} {{description=y} @{Veteran|charname_output} by calling a function / macro / script ? I would like to use that in a script, in which I modify some parts of it (e.g. the description).
1594212774
The Aaron
Roll20 Production Team
API Scripter
You should be able to load that attribute and read the contents: let attr = findObjs({ type: "attribute", characterid: "-Kt-X-OGE_Ib0UcH-KR_", name: "repeating_npcaction_-Kt-X-fj3H6XL4VdJ-Jv_npc_action"})[0];
1594250178
timmaugh
Pro
API Scripter
Would the type here be "ability"?
1594261199
The Aaron
Roll20 Production Team
API Scripter
Actually, that's a good question. I was thinking this was an attribute because it's a repeating group, but it's a roll, so I'm not sure how that's implemented. I'll need to do some testing when I've got my computer back...
1594262244

Edited 1594262294
GiGs
Pro
Sheet Author
API Scripter
It looks like its a roll button inside a repeating section, so type 'ability' should work. I think  roll buttons are implemented as abilities. They are treated as abilities for every other purpose.
If I use 'attribute' the variable attr is undefined, so it must be 'ability' - but still, I get ... {"name":"a-Greatclub","description":"","action":"%{-Kt-c0KkScXt_VooVv6b|repeating_npcaction_-Kt-WHnXbbPUw7Mou4zh_npc_action}","istokenaction":true,"_id":"-MBmqZWMBSh9QA3qjf7l","_characterid":"-Kt-c0KkScXt_VooVv6b","_type":"ability"} ... and I am looking for replacing the 'action' part .. that doesn't work yet
1594289190
GiGs
Pro
Sheet Author
API Scripter
Is that the return for the earlier ability: %{-Kt-X-OGE_Ib0UcH-KR_|repeating_npcaction_-Kt-X-fj3H6XL4VdJ-Jv_npc_action} If so it looks like its calling a second ability %{-Kt-c0KkScXt_VooVv6b|repeating_npcaction_-Kt-WHnXbbPUw7Mou4zh_npc_action} which is a bit weird.
Hm, maybe this is because I created (using !TokenAction) an ability first?
Perhaps I should explain further what I am doing right now (maybe I am doing something wrong?): 1. Creating attack-abilities (e.g. using !ta attacks): repeated_npcactions are transferred into abilities. 2. Change the name of the newly created ability manually: Add "a-" in front of it (I want to have the attacks grouped together and also this is used to trigger an event listener - I don't want to run the script wildly ;-)  ) 3. The triggered script (suggested from Scott) should replace the abbreviated code from the created ability (first code example in first message of this thread) with the expanded code (second code example). 4. The script should then modify the description of the current ability.
1594292384

Edited 1594294084
Here's the code that I am talking about: on('change:ability',(obj,prev)=>{ log(obj.get('name')) //if(!/^repeating_attack/.test(obj.get('name'))){ // return; //} --- code replaced so it cannot run wildly // only abilities with an manually added "a-" in front shall pass here if(!/^a-/.test(obj.get('name'))){ return; } let description = findObjs({ type:'ability', characterid:obj.get('characterid'), name:obj.get('name').replace(/(repeating_attack_[^_]+_).+/,"$1atk_desc") //name:obj.get('name').replace(/(repeating_npcaction_[^_]+_).+/,"$1atk_desc") -- did get funny results, e.g. "ui_flags" })[0]; log('desc: ' + description); // example from Aaron, mainly the same as above except for that replacement and it's looking at attributes let attr = findObjs({ type: "attribute", characterid: obj.get('characterid'), name: obj.get('name')})[0]; log('attr: ' + attr) if(description){ log('checkpoint 1') if(!/attacking @{target|token_id}/.test(description.get('current'))){ log('checkpoint 2') description.set({current:`${description.get('current')}\nattacking @{target|token_id}`}); log(description) //log(obj.get('description')); //),description)); } }else{ log('checkpoint 3') createObj('ability',{ characterid:obj.get('characterid'), name:obj.get('name').replace(/(repeating_attack_[^_]+_).+/,"$1atk_desc"), current:'attacking @{target|token_id}' }) } });