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

[Script] ScriptCards - My "Spiritual Successor" to PowerCards

1623331873

Edited 1623331897
Is there a way to get the current date/time into ScriptCards?  I've developed a quick note-taking capability and would like to timestamp my notes as I store them.  If not, I guess I could write an API that stuffs the system time into a state variable then pick it up from script cards.  
1623334850
timmaugh
Pro
API Scripter
Will M. said: Is there a way to get the current date/time into ScriptCards?  I've developed a quick note-taking capability and would like to timestamp my notes as I store them.  If not, I guess I could write an API that stuffs the system time into a state variable then pick it up from script cards.   That sounds like a good addition for Fetch. It already does Token and Character data, and I have Page, Campaign, and Player in the works. It makes sense to have a few system properties available, too. Then you could just drop the construction right in your command line (no matter the API) and have it included.
1623359373

Edited 1623359474
@Kurt - I've added and tested the following potential javascript that would add a datetime , date and time function to your code, with user specified hour offset .  This may not be the most elegant code, but it worked for me.  It follows your function format:       --~currDateTime|system;datetime;-5      --~currDate|system;date     --~currTime|system;time;-5 Let me know if there is a better way to communicate this kind of stuff to you, and don't want to step on your toes.  I can't believe how powerful this script is and the potential for extended is amazing.                  case "system":                   if (params.length > 1) {                     if (params[1].toLowerCase() == "datetime") {                       var timeOffset = params[2];                       var currentdate = new Date();                        var cdHour = Number(currentdate.getHours()) + Number(timeOffset);                       var datetime =                         ("00" + (currentdate.getMonth() + 1)).slice(-2) + "/" +                         ("00" + currentdate.getDate()).slice(-2) + "/" +                         currentdate.getFullYear() + " " +                         ("00" + cdHour).slice(-2) + ":" +                         ("00" + currentdate.getMinutes()).slice(-2) + ":" +                         ("00" + currentdate.getSeconds()).slice(-2);                       stringVariables[variableName] = datetime;                     }                     if (params[1].toLowerCase() == "date") {                       var currentdate = new Date();                        var cdate =                         ("00" + (currentdate.getMonth() + 1)).slice(-2) + "/" +                         ("00" + currentdate.getDate()).slice(-2) + "/" +                         currentdate.getFullYear();                       stringVariables[variableName] = cdate;                     }                     if (params[1].toLowerCase() == "time") {                       var timeOffset = params[2];                       var currentdate = new Date();                        var cdHour = Number(currentdate.getHours()) + Number(timeOffset);                       var ctime =                         ("00" + cdHour).slice(-2) + ":" +                         ("00" + currentdate.getMinutes()).slice(-2) + ":" +                         ("00" + currentdate.getSeconds()).slice(-2);                       stringVariables[variableName] = ctime;                     }                   }                   break;
1623407788

Edited 1623407885
Kurt J.
Pro
API Scripter
Will M. said: @Kurt - I've added and tested the following potential javascript that would add a datetime , date and time function to your code, with user specified hour offset .  This may not be the most elegant code, but it worked for me.  It follows your function format:       --~currDateTime|system;datetime;-5      --~currDate|system;date     --~currTime|system;time;-5 Let me know if there is a better way to communicate this kind of stuff to you, and don't want to step on your toes.  I can't believe how powerful this script is and the potential for extended is amazing.                  case "system":                   if (params.length > 1) {                     if (params[1].toLowerCase() == "datetime") {                       var timeOffset = params[2];                       var currentdate = new Date();                        var cdHour = Number(currentdate.getHours()) + Number(timeOffset);                       var datetime =                         ("00" + (currentdate.getMonth() + 1)).slice(-2) + "/" +                         ("00" + currentdate.getDate()).slice(-2) + "/" +                         currentdate.getFullYear() + " " +                         ("00" + cdHour).slice(-2) + ":" +                         ("00" + currentdate.getMinutes()).slice(-2) + ":" +                         ("00" + currentdate.getSeconds()).slice(-2);                       stringVariables[variableName] = datetime;                     }                     if (params[1].toLowerCase() == "date") {                       var currentdate = new Date();                        var cdate =                         ("00" + (currentdate.getMonth() + 1)).slice(-2) + "/" +                         ("00" + currentdate.getDate()).slice(-2) + "/" +                         currentdate.getFullYear();                       stringVariables[variableName] = cdate;                     }                     if (params[1].toLowerCase() == "time") {                       var timeOffset = params[2];                       var currentdate = new Date();                        var cdHour = Number(currentdate.getHours()) + Number(timeOffset);                       var ctime =                         ("00" + cdHour).slice(-2) + ":" +                         ("00" + currentdate.getMinutes()).slice(-2) + ":" +                         ("00" + currentdate.getSeconds()).slice(-2);                       stringVariables[variableName] = ctime;                     }                   }                   break; Looks great, Will. I'll update the next release :) And this is probably a good way to communicate things like this. Folks that want to jump on it before it gets officially added can update their own script, and I can integrate it easily enough. I'll probably add some error checking if the user doesn't specify an offset, etc. to prevent possible sandbox issues.
1623410397
Andrew R.
Pro
Sheet Author
Warning! Timezones are not just hour offsets. South Australia, for example. 
1623442495

Edited 1623442842
@Kurt - It appears that scriptcards is not using odd and even rows to cover all buttons.  Or is it my code?  Note 1st letter of 1st button missing and last button extending beyond row. --+|[b][c][button]Time to Rage!::~MacrosFight&Barb|Rage[/button] [button]Reckless Attack!::~MacrosFight&Barb|Reckless[/button][/b][/c] --+|[b][c][button] Relentless Endurance ::~MacrosFight&Barb| Relentless [/button][/b][/c] Gets me: ime to Rage!   Reckless Attack! Relentless Endurance   Speak With Animals Relentless Endurance
1623445223

Edited 1623445264
Kurt J.
Pro
API Scripter
Michael C. said: @Kurt - It appears that scriptcards is not using odd and even rows to cover all buttons.  Or is it my code?  Note 1st letter of 1st button missing and last button extending beyond row. --+|[b][c][button]Time to Rage!::~MacrosFight&Barb|Rage[/button] [button]Reckless Attack!::~MacrosFight&Barb|Reckless[/button][/b][/c] --+|[b][c][button] Relentless Endurance ::~MacrosFight&Barb| Relentless [/button][/b][/c] Gets me: ime to Rage!   Reckless Attack! Relentless Endurance   Speak With Animals Relentless Endurance Can you post some more context around those lines? When I run just those in a script, I get normal output: So my guess is there is something else happening at some point in the script. Especially since the "Speak with Animals" button seems to come from nowhere, and the relentless endurance button is repeated.
@Kurt - I think there was something going on with Roll20 as I kept getting the red message about server down.&nbsp; The script I was working on was: !scriptcard &nbsp; {{ &nbsp; --#title|Barbarian Abilities &nbsp; --#sourceToken|@{selected|token_id} &nbsp; --#emoteText|[*S:character_name] Uses &nbsp; an Ability &nbsp; --#titleCardFont|# 196F3D &nbsp; --#titleCardBackground|#90BB2B &nbsp; --#evenRowBackground| #ff0000 &nbsp; --#evenRowFontColor|#ffff00 &nbsp; --#oddRowBackground| #DFFF00 &nbsp; --#oddRowFontColor|#267150 --#debug|1 --+|[img]<a href="https://media.giphy.com/media/3ohzdODFjYLku719ny/giphy.gif[/img]" rel="nofollow">https://media.giphy.com/media/3ohzdODFjYLku719ny/giphy.gif[/img]</a> --+|[b][c][button]Time to Rage!::~MacrosFight&amp;Barb|Rage[/button] [button]Reckless Attack!::~MacrosFight&amp;Barb|Reckless[/button][/b][/c] --+|[b][c][button] Relentless Endurance ::~MacrosFight&amp;Barb| Relentless [/button][/b][/c] }} Speak with animals was in another macro I had been working on.&nbsp;&nbsp;
Ran into a condition issue.&nbsp; My code:&nbsp; &nbsp; &nbsp; &nbsp; --?"[*T:npc_condition_immunities]" -inc “Charmed"|Immune&nbsp; Creature:&nbsp;&nbsp; Condition Immunities Charmed, exhaustion, frightened, poisoned Debug: "Line Counter: 17, Tag:?\"Charmed, exhaustion, frightened, poisoned\" -inc “Charmed\", Content:Immune" "Condition \"Charmed, exhaustion, frightened, poisoned\" -inc “Charmed\" evaluation result: false" Why is the condition false?
You might try taking away the double quotes from "Charmed".&nbsp; It may be looking literally for "Charmed" with the double quotes attached.&nbsp; Also, you might try converting all to lowercase just in case it is doing a case-sensitive comparison.&nbsp;&nbsp;
1623587461

Edited 1623588264
@Will - Thanks, I had tried lowercase first (didn't work) then looked back at the&nbsp; npc_condition_immunities &nbsp;variable on the NPC character sheet and it was sentence case so I tried that.&nbsp; As noted above, no luck either.&nbsp; I tried removing the "" from Charmed&nbsp; but all it resulted in was errors. Edit: correction: it just ignores the condition.&nbsp; If I remove all "" from the line I get the following error: "ScriptCards conditional error: Condition contains an invalid clause joiner on line. Only -and and -or are supported. Assume results are incorrect. Charmed, exhaustion, frightened, poisoned -inc Charmed" "Condition Charmed, exhaustion, frightened, poisoned -inc Charmed evaluation result: false"
Need help on sleep spell.&nbsp; Note: I have not tested this script, strictly an exercise in logic and flow at moment. (Though if there is anything wrong feel free to comment.)&nbsp; Am trying to think of a way to pass the inRange array of Kurt's fame into a routine that will reorder the tokens found into a lowest to highest HP array.&nbsp; The idea is something like: &nbsp; &nbsp; &nbsp; --/?????Check to find token with lowest - highest hp &amp; reorder array loop??????? &nbsp;&nbsp; &nbsp; --:loopDisplay|check to see if sleep points are higher than lowest token hp &nbsp; &nbsp; &nbsp; &nbsp; --?[$SleepPoints] -gt [*[&amp;tokenid]:hp]|&gt;Sleep|endMacro &nbsp; &nbsp; --~tokenid|array;getnext;inRange &nbsp; &nbsp; --?[&amp;tokenid] -ne ArrayError|loopDisplay &nbsp; &nbsp; &nbsp; --^endMacro| &nbsp; &nbsp; &nbsp; --:Sleep| set status, subtract hp from sleep points, go to next token --@token-mod| _ignore|selected _ids _set statusmarkers|Sleep &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; --=SleepPoints|[$SleepPoints] - [*T:hp] &nbsp; &nbsp; &nbsp;&nbsp; --&lt;| &nbsp;&nbsp; &nbsp; --:endMacro| &nbsp; &nbsp; --X| Any idea how to reorder the array?
1623599729

Edited 1623600740
Michael C. said: @Will - Thanks, I had tried lowercase first (didn't work) then looked back at the&nbsp; npc_condition_immunities &nbsp;variable on the NPC character sheet and it was sentence case so I tried that.&nbsp; As noted above, no luck either.&nbsp; I tried removing the "" from Charmed&nbsp; but all it resulted in was errors. Edit: correction: it just ignores the condition.&nbsp; If I remove all "" from the line I get the following error: "ScriptCards conditional error: Condition contains an invalid clause joiner on line. Only -and and -or are supported. Assume results are incorrect. Charmed, exhaustion, frightened, poisoned -inc Charmed" "Condition Charmed, exhaustion, frightened, poisoned -inc Charmed evaluation result: false" @Michael - Did a quick test and this works for me.&nbsp; You need quotes around the list of Immunities due to the potential for special characters like commas, but not around the word charmed.&nbsp; Dealing with special characters and replacements can get a little tricky in ScriptCards.&nbsp; I would write up a short white-paper on it, but I am not the expert.&nbsp; I've done things like parsed the JSON text for the list of tokens in the TurnOrder list and it wasn't fun, just a lot of trial by error till I finally got it to work.&nbsp;&nbsp; !script {{&nbsp;&nbsp; &nbsp; --#title|Test Charmed &nbsp; --#titleCardBackground|#932729 &nbsp; --#whisper|self &nbsp; --#oddRowBackground|#FFFFFF &nbsp; --#evenRowBackground|#FFFFFF &nbsp; --#sourceToken|@{selected|token_id}&nbsp;&nbsp; &nbsp; --#targetToken|@{target|token_id}&nbsp;&nbsp; &nbsp; --#debug|1 &nbsp; --&amp;Immunities|[*T:npc_condition_immunities] &nbsp; --~Immunities|string;tolowercase;[&amp;Immunities] &nbsp; --*Immunities|[&amp;Immunities] &nbsp; --?"[&amp;Immunities]" -inc charmed|NOCHARM|CHARM &nbsp; --:CHARM| &nbsp; --+|[*T:t-name] can be charmed!!! &nbsp; --#leftSub|Very Charmable! &nbsp; --^DONE| &nbsp; --:NOCHARM| &nbsp; --+|[*T:t-name] is IMMUNE from being charmed!!! &nbsp; --#leftSub|Not Charming at all!&nbsp; &nbsp; --^DONE| &nbsp; --:DONE| &nbsp; --X| }}
1623600373

Edited 1623601031
Michael C. said: Need help on sleep spell.&nbsp; Note: I have not tested this script, strictly an exercise in logic and flow at moment. (Though if there is anything wrong feel free to comment.)&nbsp; Am trying to think of a way to pass the inRange array of Kurt's fame into a routine that will reorder the tokens found into a lowest to highest HP array.&nbsp; The idea is something like: &nbsp; &nbsp; &nbsp; --/?????Check to find token with lowest - highest hp &amp; reorder array loop??????? &nbsp;&nbsp; &nbsp; --:loopDisplay|check to see if sleep points are higher than lowest token hp &nbsp; &nbsp; &nbsp; &nbsp; --?[$SleepPoints] -gt [*[&amp;tokenid]:hp]|&gt;Sleep|endMacro &nbsp; &nbsp; --~tokenid|array;getnext;inRange &nbsp; &nbsp; --?[&amp;tokenid] -ne ArrayError|loopDisplay &nbsp; &nbsp; &nbsp; --^endMacro| &nbsp; &nbsp; &nbsp; --:Sleep| set status, subtract hp from sleep points, go to next token --@token-mod| _ignore|selected _ids _set statusmarkers|Sleep &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; --=SleepPoints|[$SleepPoints] - [*T:hp] &nbsp; &nbsp; &nbsp;&nbsp; --&lt;| &nbsp;&nbsp; &nbsp; --:endMacro| &nbsp; &nbsp; --X| Any idea how to reorder the array? I can think of 2 approaches: 1. You may need an write an old fashioned bubble sort to order the list.&nbsp; Here is a scriptcard post &nbsp;(Thanks to @David M) with code you may be able to use.&nbsp;&nbsp; 2. Brute force it.&nbsp;&nbsp; &nbsp; &nbsp; Build InRange and Sleepable (some creatures are immune) Token List &nbsp; &nbsp; Loop until out of SleepHP to deliver or out of InRange Tokens &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; Step through the current InRange List, recording the minimum HP and associated TokenId &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; Reduce SleepHP by TokenHP (one with the minimum HP) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; Mark Token as sleeping&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; Pop Token off the InRange Tokens list &nbsp; &nbsp; End Loop
1623601788

Edited 1623601919
David M.
Pro
API Scripter
EDIT - I missed that Will already linked the algorithm (or maybe the post was edited to include it) Here is the link to the&nbsp; die roll bubble sort algorithm . It's likely to be tricky to adapt for arrays, though, as the "BubbleUp" function currently only swaps single roll variables. Ideally it would swap the indices of the compared values - there is a removeat array function but doesn't look like there is a splice-type function to add an element at a given index so not sure how clean it would end up being.&nbsp; Given that apparent limitation, Will's brute force option 2 pseudo-code might be the way to go.
Will M. said: Michael C. said: @Will - Thanks, I had tried lowercase first (didn't work) then looked back at the&nbsp; npc_condition_immunities &nbsp;variable on the NPC character sheet and it was sentence case so I tried that.&nbsp; As noted above, no luck either.&nbsp; I tried removing the "" from Charmed&nbsp; but all it resulted in was errors. Edit: correction: it just ignores the condition.&nbsp; If I remove all "" from the line I get the following error: "ScriptCards conditional error: Condition contains an invalid clause joiner on line. Only -and and -or are supported. Assume results are incorrect. Charmed, exhaustion, frightened, poisoned -inc Charmed" "Condition Charmed, exhaustion, frightened, poisoned -inc Charmed evaluation result: false" @Michael - Did a quick test and this works for me.&nbsp; You need quotes around the list of Immunities due to the potential for special characters like commas, but not around the word charmed.&nbsp; Dealing with special characters and replacements can get a little tricky in ScriptCards.&nbsp; I would write up a short white-paper on it, but I am not the expert.&nbsp; I've done things like parsed the JSON text for the list of tokens in the TurnOrder list and it wasn't fun, just a lot of trial by error till I finally got it to work.&nbsp;&nbsp; !script {{&nbsp;&nbsp; &nbsp; --#title|Test Charmed &nbsp; --#titleCardBackground|#932729 &nbsp; --#whisper|self &nbsp; --#oddRowBackground|#FFFFFF &nbsp; --#evenRowBackground|#FFFFFF &nbsp; --#sourceToken|@{selected|token_id}&nbsp;&nbsp; &nbsp; --#targetToken|@{target|token_id}&nbsp;&nbsp; &nbsp; --#debug|1 &nbsp; --&amp;Immunities|[*T:npc_condition_immunities] &nbsp; --~Immunities|string;tolowercase;[&amp;Immunities] &nbsp; --*Immunities|[&amp;Immunities] &nbsp; --?"[&amp;Immunities]" -inc charmed|NOCHARM|CHARM &nbsp; --:CHARM| &nbsp; --+|[*T:t-name] can be charmed!!! &nbsp; --#leftSub|Very Charmable! &nbsp; --^DONE| &nbsp; --:NOCHARM| &nbsp; --+|[*T:t-name] is IMMUNE from being charmed!!! &nbsp; --#leftSub|Not Charming at all!&nbsp; &nbsp; --^DONE| &nbsp; --:DONE| &nbsp; --X| }} Lol.&nbsp; A sense of humor is definitely needed to write macros.&nbsp; This works for me as well.&nbsp; Thanks.&nbsp; Two questions - I have looked throughout the wiki and can find no reference to the&nbsp; --* command.It's obviously not typo, what is its function?&nbsp;&nbsp; --*Immunities|[&amp;Immunities] Also, I noted before in Kurt's fireball script the use of&nbsp; &nbsp; --?" X [*[%1%]:npc_[%8%]_save_base]"&nbsp; &nbsp; What is the purpose of the 'X' here? Could it be used to solve the issue?
1623619373

Edited 1623619570
David M.
Pro
API Scripter
Michael, I finally got a chance to look at this. I came up with something using the BubbleSort algorithm, but it's not very pretty. I basically took the array containing all the tokens on the page and filtered for range and npc_condition_immunites, but instead of populating an inRange array, I populated three indexed variables for hp, name, and tokenid (so hp0, hp1, name0, name1, etc). Then edited the BubbleUp procedure to do the index swapping for all three variable sets. You could add or subtract any variables you don't need (like probably name), but I figured you would need tokenid to do your condition marker. If you remove name, be sure to remove the corresponding block from the BubbleUp procedure. Currently I am just outputting the varaible sets before and after sorting, but you should be able to easily add the stuff you want to do with the sorted values. !script {{ --#title|Sorting values from arrays Example --:(1) GET ALL TOKENS INTO THE "allTokens" ARRAY| will have blank 1st element to be removed later --~|array;pagetokens;allTokens;@{selected|token_id} --:(2) CREATE THE "inRange" ARRAY TO HOLD TOKENS IN RANGE| --~|array;define;inRange; --:(3) PREP ARRAY FOR LOOP| if no array elements then end macro --~tokenid|array;getfirst;allTokens --?[&amp;tokenid] -eq ArrayError|endOutput --:(4) FIND ALL TOKENS IN RANGE| add indexed roll variables for tokID, name, &amp; hp --=numToks|0 --=i|0 --+~~~Tok Order BEFORE sorting~~~| --:RangeLoop| --:TOKEN MUST BE ON OBJECTS OR GMLAYER AND TYPE MUST INCLUDE UNDEAD| --?[*[&amp;tokenid]:t-layer] -ne objects -and [*[&amp;tokenid]:t-layer] -ne gmlayer|NextToken --?"[*[&amp;tokenid]:npc_condition_immunities]" -inc "sleep" -or [*[&amp;tokenid]:t-bar1_value] -lt 1|NextToken --:CHECK DISTANCE IN UNITS. 20ft is 4UNITS| --~dist|euclideandistance;@{selected|token_id};[&amp;tokenid] --?[$dist] -gt 4|NextToken --:ADD TO THE "ARRAYS" OF VARIABLES| --&amp;tokID[$i.Total]|[&amp;tokenid] --&amp;name[$i.Total]|[*[&amp;tokenid]:t-name] --=hp[$i.Total]|[*[&amp;tokenid]:t-bar1_value] --=numToks|[$numToks] + 1 --:OUTPUT PRE_SORTED VALS| --+Tok[$i.Total]|[&amp;name[$i.Total]], [$hp[$i.Total]], [&amp;tokID[$i.Total]] --=i|[$i] + 1 --/~|array;add;inRange;[&amp;tokenid] --:NextToken| --~tokenid|array;getnext;allTokens --?[&amp;tokenid] -ne ArrayError|RangeLoop --:(5) SORT ALL "ARRAY" VARIABLES BY HP VALUE WITH A BUBBLE SORT| --=max_i|[$i] --=i|0 --:OuterLoop| --=i|[$i]+1 --=j|[$i] --:InnerLoop| --=j|[$j]+1 --?[$hp[$i.Total]] -gt [$hp[$j.Total]] |&gt;BubbleUp;[$i.Total];[$j.Total] --?[$j.Total] -lt [$NumDice.Total]|InnerLoop --?[$i.Total] -lt [$max_i.Total]|OuterLoop --:(6) OUTPUT THE SORTED VARIABLES| --=i|0 --+~~~Tok Order AFTER sorting~~~| --:SortLoop| --+Tok[$i.Total]|[&amp;name[$i.Total]], [$hp[$i.Total]], [&amp;tokID[$i.Total]] --=i|[$i]+1 --?[$i.Total] -lt [$numToks.Total]|SortLoop --:End| --X| --:PROCEDURES| --:BubbleUp| accepts i, j as parameters. Swaps var[i] &amp; var[j] for three variables --=Temp|[$hp[%2%]] --=hp[%2%]|[$hp[%1%]] --=hp[%1%]|[$Temp] --&amp;Temp|[&amp;tokID[%2%]] --&amp;tokID[%2%]|[&amp;tokID[%1%]] --&amp;tokID[%1%]|[&amp;Temp] --&amp;Temp|[&amp;name[%2%]] --&amp;name[%2%]|[&amp;name[%1%]] --&amp;name[%1%]|[&amp;Temp] --&lt;| }} Sample output:
@Will/David David M. said: EDIT - I missed that Will already linked the algorithm (or maybe the post was edited to include it) Here is the link to the&nbsp; die roll bubble sort algorithm . It's likely to be tricky to adapt for arrays, though, as the "BubbleUp" function currently only swaps single roll variables. Ideally it would swap the indices of the compared values - there is a removeat array function but doesn't look like there is a splice-type function to add an element at a given index so not sure how clean it would end up being.&nbsp; Given that apparent limitation, Will's brute force option 2 pseudo-code might be the way to go. I looked through the bubblesort.&nbsp; Not sure how to keep the tokenid associated with the token's hp so maybe brute force has it.&nbsp; Thanks, Guys!
1623622396
David M.
Pro
API Scripter
@Michael, see my last post :)
1623625227

Edited 1623625353
--*Header|More text Is a GM debug output command.&nbsp; It outputs results similar to --+header|text but only whispered to the GM.&nbsp; I believe it's documented as one of the last commands in the WIKI table of commands.&nbsp; do a search for --* on the wiki page.
@David - Thanks! The bubblesort looks very good - had not understood how the indexing worked before - and I think I can modify it to work with the macro.&nbsp; I was working through it and noted your use of:&nbsp;&nbsp;&nbsp; --?"[*[&amp;tokenid]:npc_condition_immunities]” -inc “sleep”&nbsp; Not sure why this works and my&nbsp;&nbsp; --?"[*[&amp;tokenid]:npc_condition_immunities]” -inc “charmed”&nbsp; line&nbsp; that Will was trying to help me with above&nbsp; didn't? &nbsp;&nbsp; (Actually, it may be that 'sleep' isn't a condition?) &nbsp; Is this another of the Roll20 inconsistencies Will mentioned?
@Will - thanks.&nbsp; ::Doh::&nbsp; Didn't check the chart, was looking through the table of contents and trying to find it scrolling through command descriptions.
1623673892
David M.
Pro
API Scripter
I was actually having trouble finding any 5e npc with sleep immunity auto-populated in an attribute. Your probably right that they don't consider sleep a condition. I grabbed a drow elf, for example, and the npc_condition_immunities was blank even though the sheet clearly denotes in text that they are immune to sleep. I ended up typing it in manually. So, YMMV with that one. Might want to have a SleepImmunity ChatSetAttr macro handy to populate the immunities attribute with "sleep" if your party uses that spell often and/or if you have a bunch of different sleep-immune creatures.&nbsp;
In the sleep spell it says " Undead and creatures immune to being&nbsp; charmed &nbsp;aren't affected by this spell."&nbsp; Which means that you need to do two tests, one for npc_type&nbsp; containing undead and one for charmed immunity.&nbsp;&nbsp;
BTW, I plan to borrow that new bubble sort.&nbsp; I've got a number of tools I've built that inventory and display page assets within a user-defined range based on a selected token.&nbsp; It will be nice to now sort them by how close they are to the selected token.&nbsp;&nbsp;
@David - still an excellent macro though and I had seen the sleep spell condition language Will pointed out.&nbsp; BTW - YMMV?&nbsp; Don't know that one... @Will - I saw that as well and actually didn't know why the bar1_value condition was there so replaced it with your&nbsp; &nbsp; --:ImmuneToCharm| &nbsp; &nbsp; --&amp;Immunities|[*T:npc_condition_immunities] &nbsp; &nbsp; --~Immunities|string;tolowercase;[&amp;Immunities] &nbsp; &nbsp; --?"[&amp;Immunities]" -inc charmed|NextToken and --?“[*[&amp;tokenid]:npc_type]” -inc “undead”|NextToken But once again, don't understand why undead line works this way (it does) and we have to go through your gosub to get the npc_condition_immunities to work.&nbsp;
Kurt J. said: ScriptCards v 1.3.1 - Some Rewrites and Tweaks Version 1.3.1 of ScriptCards is now available on the Development GIST . If all goes well with this version, I'm going to take a pause in making new changes and move this version forward to OneClick. Theoretically the changes in this version should go unnoticed unless you were trying to nest references - which should work as logically expected now. I've tested 1.3.1 with my most complicated cards and they seem to function normally, but please let me know if you run into issues. Here are the updates: Behavior Change:&nbsp; Rewrote all content substitution code as a single function that works from the innermost set of references outward, so something like&nbsp; &amp;wow[$count[&amp;suffix]]] will process [&amp;suffix] first, then [$countX] where X is the result of [&amp;suffix] and finally [&amp;wow1] where 1 is the result of [$countX]. This makes the language more logical and variable resolution more deterministic. It&nbsp;is also a huge performance improvement, since the way variables were replaced previously was&nbsp;highly non-optimal. NOTE : as a side effect of this change, some of the uncommonly used settings ( disablerollvariableexpansion and similar) will not function at this time. They were primarily for debugging purposes and will return in a future update, but won't have an effect at this time. Array Referencing : It is now possible to reference array items directly with the [@arrayName(index)] syntax. The first element of the array is index 0, etc. Additional Roll Variable Suffix : You can now use ".Raw" suffix when referencing a roll variable to skip formatting the result as a roll. This shouldn't normally be necessary, as roll formatting is only done on --+ and --* lines, but it is available, especially given the special note in the previous item. Behavior Change: When generating tooltips (and only &nbsp;when generating tooltips) for roll variable display, the "~" character will be removed. This makes it easier to hide what&nbsp;look like rolls from the chat server when referencing nested values (ie, [~[&amp;shortSaveNameUpper]~])&nbsp;when you just want the value of the variable in square brackets as an explanation, since using&nbsp;[[&amp;shortSaveNameUpper]] would look like an inline roll to the chat server. Feature Update:&nbsp; Added support for new token properties added to Roll20 on 2021-06-03 ( bar_location , compact_bar , light_sensitivity_multiplier , and night_vision_effect ). As with all token references, these are made with the "t-" prefix. Hi Kurt, i was running my game with 1.2.8 and I tried to upgrade to your las version..... Before I cloned my game to be safe ^^ In surface nothing seemed to have change....But when it gets to my complex re-entrant dice rollers (for Shaan RPG - a few pages before) it alle screwed up.... trying to figure out by myself but meanwhile, reverted to 1.2.8!
@Kurt - What is the purpose of the X in the&nbsp; &nbsp;--?" X [*[%1%]:npc_[%8%]_save_base]"&nbsp; line of your fireball script?
1623778103
Kurt J.
Pro
API Scripter
Michael C. said: @Kurt - What is the purpose of the X in the&nbsp; &nbsp;--?" X [*[%1%]:npc_[%8%]_save_base]"&nbsp; line of your fireball script? Been away for a few days :) Have a lot of posts to go through, but essentially this is an old DOS batch file trick. If the value of referenced in the condition could potentially be blank/empty you might end up with something like : --?"" -eq 5| which, when the quotes are removed would be : --?-eq 5| which will throw a condition error because there isn't a left-hand value. Adding the "X" ensures there will always be at least a character there to compare to. In the case that what's inside is blank, you'll get: --?X -eq 5| which is a valid comparison.
@Kurt - I see (and that pretty much dates you if its an old DOS trick)&nbsp; ;-)&nbsp; So, to prevent that creating an inequality if there is a value in the condition, you preface the matching variable by adding an "X" to it also?&nbsp; Interesting....
1623813981

Edited 1623814283
Has anyone figured out how to generate a roll template as output? e.g. !script {{ --#sourceToken|@(Kimmuriel|token_id) --#targetToken|@(Ector Moris|token_id) --#hideCard|1 --?"[*S:initiative_style]" -ninc kh|=Init;1d20 + [*S:initiative_bonus] [INIT]|=Init;2d20kh1 + [*S:initiative_bonus][*S:pbd_safe] [INIT] --=EctorInit|[$Init] - .001 --~|turnorder;replacetoken;[*S:t-id];[$Init.Total] --~|turnorder;replacetoken;[*T:t-id];[$EctorInit.Total] --e|&amp;{template:simple} {&amp;#123;rname=INITIATIVE&amp;#125;} &amp;#123;{mod=[*S:initiative_bonus]}&amp;#125; &amp;#123;{r1=[$Init.Total]}&amp;#125; &amp;#123;{normal=1}&amp;#125; {{charname=[*S:character_name]}&amp;#125; {&amp;simple} {&amp;log} --/| }} What I have in my game is a situation where Kimmuriel the PC has an NPC that goes immediately after him in the initiative order. I'd prefer not to manually add the NPC every time the PC rolls initiative, so I want this to take the place of the standard initiative roll. At the same time, I want the output to chat to be the same as for other characters. In the alternative, if there were a way to find the turnorder value for Kimmuriel, and modify the initiative macro for Ector Moris the NPC to just immediately follow it. Something like [*S:t-tracker] @Kurt: Tangent: the wiki says that the proper reference for a token_id is [*S:t-token_id] But that hasn't worked.
1623860344
timmaugh
Pro
API Scripter
Colin C. said: Has anyone figured out how to generate a roll template as output? You're in the right vein if you just want to generate a roll template as one passing part of your output. Your {&amp;simple} will turn the WHOLE message to a simple/flat output, which I don't think is what you want. I'm figuring that you might have other cool things going on in you ScriptCard, and the roll template output is just one part of it. In that case, try this: --@forselected(~)| {~&amp;template:simple} {&amp;#123;rname=INITIATIVE&amp;#125;} &amp;#123;{mod=[*S:initiative_bonus]}&amp;#125; &amp;#123;{r1=[$Init.Total]}&amp;#125; &amp;#123;{normal=1}&amp;#125; {{charname=[*S:character_name]}&amp;#125; {^&amp; select @(Kimmuriel|token_id)} {~&amp;simple} That should provide a workflow something like: Macro dispatched Roll20 parsing (doesn't see roll template construction) Meta script parsing (Fetch construction) -- SelectManager won't see the {&amp;select...} nor will ZeroFrame see the {&amp;simple} or {&amp;template...} constructions ScriptCard parsing (subbing in all values) ScriptCard issues the forselected but first removes the ^ character (provided you haven't changed the default escape character. This exposes the {&amp;select...} construction for the next call. &nbsp; &nbsp; new message is dispatched: !forselected(~) {~&amp;template:simple}... {&amp;select -M1234567890abacdef} {~&amp;simple} &nbsp; &nbsp; Roll20 parsing &nbsp; &nbsp; meta script parsing (Kimmuriel is virtually selected) &nbsp; &nbsp; forselected parsing now sends the command for each selected token (of which we only have one -- Kimmuriel), but first it removes the ~ escape character (defined in the forselected handle: forselected (~) &nbsp; &nbsp; &nbsp; &nbsp; a NEW message is dispatched that looks like your roll template: !{&amp;template:simple}...{&amp;simple} &nbsp; &nbsp; &nbsp; &nbsp; Roll20 parsing doesn't see the template construct (it's a ZeroFrame construct, with the ampersand and brace reversed) &nbsp; &nbsp; &nbsp; &nbsp; Meta script parsing -- ZeroFrame sees the {&amp;template...} construct and the {&amp;simple} construct... and should (finally) dispatch the final message This message is a flat message containing your roll template This view of the sausage factory presented to you by "All the Things You Never Wanted to Know... dot com."
1623861709
David M.
Pro
API Scripter
:-O&nbsp;
1623871819

Edited 1623873340
timmaugh said: Colin C. said: Has anyone figured out how to generate a roll template as output? --@forselected(~)| {~&amp;template:simple} {&amp;#123;rname=INITIATIVE&amp;#125;} &amp;#123;{mod=[*S:initiative_bonus]}&amp;#125; &amp;#123;{r1=[$Init.Total]}&amp;#125; &amp;#123;{normal=1}&amp;#125; {{charname=[*S:character_name]}&amp;#125; {^&amp; select @(Kimmuriel|token_id)} {~&amp;simple} That got me really close! One thing that I was banging my head against the wall about was that your line gave me absolutely no output whatsoever. . . because I didn't realize that ZeroFrame was not installed. Oops. The next piece was that, with the ZeroFrame/deferral blah blah, the HTML escaping wasn't working properly, so I reverted to } characters and escaped those out through forselected: !script {{ --#hideCard|1 --#debug|1 --#sourceToken|@(Kimmuriel|token_id) --#targetToken|@(Ector Moris|token_id) --?"[*S:initiative_style]" -ninc kh|=Init;1d20 + [*S:initiative_bonus][*S:pbd_safe] [INIT]|=Init;2d20kh1 + [*S:initiative_bonus][*S:pbd_safe] [INIT] --&amp;Init|[$Init.Text] --=EctorInit|[$Init] - .001 --~|turnorder;replacetoken;[*S:t-id];[$Init.Total] --~|turnorder;replacetoken;[*T:t-id];[$EctorInit.Total] --@forselected(*)|{*&amp; template:simple} {{rname=INITIATIVE}*} {{mod=[*S:initiative_bonus]}*} {{r1=[$Init][~[&amp;Init]~]}*} {{normal=1}*} {{charname=[*S:character_name]}*} {^&amp; select @(Kimmuriel|token_id)} {*&amp;simple*} --/| }} I had to change the escape character because of the ScriptCard settings for tooltips. I also had to add a blank comment line; otherwise, ScriptCards conflates the trailing } from {*&amp;simple*} to be part of a }} construction, which closes that card too early. Two things left: Make the font size of the roll the same as it is for when the other PCs roll. The output here is smaller for some reason. I lose the tool-tip for mouseovering the roll value in the roll template output. I get the text of the tooltip *inside* the roll value display&nbsp; I've tried a couple different constructions for the tooltip, but it doesn't seem to be working.
Greetings, I have been using Power Cards for Years now and many Table that I have made that are something like the following. !power {{ --name|@{selected|token_name}’s Loot! --Looting:|@{selected|character_name} rolls a [[ [$R] 1d100]] to loot the body. -- ?? $R == 1 ?? | [[2D6]] Platinum coins -- ?? $R == 2 ?? | [[8D6]] Gold coins -- ?? $R == 3 ?? | White Marble Chess Piece (Queen) -- ?? $R == 4 ?? | [[1D10]] Potions of Health -- ?? $R == 5 ?? | Brest Plate +2 Resist Psychic -- ?? $R == 6 ?? | [[1D6]] Flask of Alchemist's fire -- ?? $R == 7 ?? | Adamantine Greataxe -- ?? $R == 8 ?? | 1 gallon of grog (4 sp) -- ?? $R == 9 ?? | Sword and Dagger -- ?? $R == 10 ?? | [[2D6]] Gems worth [[1D6*10]] gold each! -- ?? $R == 89 ?? | An iron Ingot [[4D4]] lbs. -- ?? $R == 90 ?? | Fancy pocket watch with a fish face on the plate cover -- ?? $R == 91 ?? | [[3D6]] small black coins of unknown origin -- ?? $R == 92 ?? | Handy Haversack -- ?? $R == 93 ?? | Book – Almonds’ and Berries – The love of a druid -- ?? $R == 94 ?? | Sword of First Strike -- ?? $R == 95 ?? | Gold and Ivory Dice -- ?? $R == 96 ?? | Drum -- ?? $R == 97 ?? | Everbright Lantern -- ?? $R == 98 ?? | Gloves of Missile Snaring -- ?? $R == 99 ?? | It’s a Trap – (Darts), you take [[9D9]] piercing Damage! -- ?? $R == 100 ?? | WOW ! make [[2D10]] more picks and keep them all. }} I would love to switch over to scrptcards and would like to know how I could go about doing all the rolls and use the new formating? I have not been a programer for many many years and have fallen to simpler things now. Any and all advice would be helpful. Thank you all for your time.
1623874962
timmaugh
Pro
API Scripter
Colin C. said: Two things left: Make the font size of the roll the same as it is for when the other PCs roll. The output here is smaller for some reason. I lose the tool-tip for mouseovering the roll value in the roll template output. 1. Not sure what you're seeing as different... if the other PCs use the same built-in roll template and have a differently-sized output, I don't think that is an API thing. If they are using a ScriptCard output that formats itself, that kind of formatting you're not going to get in a built-in roll template like what you're using here. Maybe you could be more specific? 2. That may be because ScriptCard is handling the inline roll itself, but we've left the SC message behind 2 or 3 messages ago by the time you get your templated output. I'm not sure what this SC line does for you: --?"[*S:initiative_style]" -ninc kh|=Init;1d20 + [*S:initiative_bonus][*S:pbd_safe] [INIT]|=Init;2d20kh1 + [*S:initiative_bonus][*S:pbd_safe] [INIT] It looks like it reads the "initiative_style" attribute of the selected character (?) and applies the necessary roll. If you only need this to determine the roll to make (nothing else from SC), then you might be able to do this with a deferred inline roll using the forselected escape character (we've been using the ~): [~[ ... ]~] If you can use SC to put what you want the roll equation to be inside of that structure, the roll should happen when the last message is sent (forselected runs the actual template command), and ZeroFrame should preserve the hover information of the roll. (We could also do this with metascripts, but it looks like you have most of the apparatus already build for SC, so we can just run with that.) Full disclosure: I had some difficulties with a similar kind of deferral in my initial testing of the metascripts, which is why ZeroFrame has its own built-in deferral pattern. If you run into a problem with this, we can employ one more meta trick to utilizing both the forselected deferral *and* the ZF deferral... but hopefully it won't come to that. Another possibility is that Kurt can share what/how the hover output is maintained for his in-script built rolls, and how to preserve them for the command line sent to forselected... which we can try to preserve with meta-tricks as necessary.&nbsp; I think that your [$Init.total] might be where you are going from a full-fledged inline roll (with mouse over pop-up) to a simple, flat value.
timmaugh said: Colin C. said: Two things left: Make the font size of the roll the same as it is for when the other PCs roll. The output here is smaller for some reason. I lose the tool-tip for mouseovering the roll value in the roll template output. 1. Not sure what you're seeing as different... if the other PCs use the same built-in roll template and have a differently-sized output, I don't think that is an API thing. If they are using a ScriptCard output that formats itself, that kind of formatting you're not going to get in a built-in roll template like what you're using here. Maybe you could be more specific? 2. That may be because ScriptCard is handling the inline roll itself, but we've left the SC message behind 2 or 3 messages ago by the time you get your templated output. I'm not sure what this SC line does for you: --?"[*S:initiative_style]" -ninc kh|=Init;1d20 + [*S:initiative_bonus][*S:pbd_safe] [INIT]|=Init;2d20kh1 + [*S:initiative_bonus][*S:pbd_safe] [INIT] It looks like it reads the "initiative_style" attribute of the selected character (?) and applies the necessary roll. If you only need this to determine the roll to make (nothing else from SC), then you might be able to do this with a deferred inline roll using the forselected escape character (we've been using the ~): [~[ ... ]~] If you can use SC to put what you want the roll equation to be inside of that structure, the roll should happen when the last message is sent (forselected runs the actual template command), and ZeroFrame should preserve the hover information of the roll. (We could also do this with metascripts, but it looks like you have most of the apparatus already build for SC, so we can just run with that.) Full disclosure: I had some difficulties with a similar kind of deferral in my initial testing of the metascripts, which is why ZeroFrame has its own built-in deferral pattern. If you run into a problem with this, we can employ one more meta trick to utilizing both the forselected deferral *and* the ZF deferral... but hopefully it won't come to that. Another possibility is that Kurt can share what/how the hover output is maintained for his in-script built rolls, and how to preserve them for the command line sent to forselected... which we can try to preserve with meta-tricks as necessary.&nbsp; I think that your [$Init.total] might be where you are going from a full-fledged inline roll (with mouse over pop-up) to a simple, flat value. I need to use ScriptCards because this particular PC has an NPC that immediately follows them in the initiative order, so the goal is whenever the PC rolls initiative, the NPC is shunted in immediately after them in the tracker. Since there's no way (that I know of) to retrieve the turn order value of a token, I'm using ScriptCards to perform the roll for the PC, and then subtracting a very small difference for the NPC, and putting them both in the turn order at the same time. You are correct about what the "initiative style" line does. I need ScriptCards to perform the roll (rather than SM or ZF or the chat server) because I use ScriptCards to adjust the turn order for both tokens at the same time. !script {{ --#hideCard|1 --#debug|1 --#sourceToken|@(Kimmuriel|token_id) --#targetToken|@(Ector Moris|token_id) --?"[*S:initiative_style]" -ninc kh|=Init;1d20 + [*S:initiative_bonus][*S:pbd_safe] [INIT]|=Init;2d20kh1 + [*S:initiative_bonus][*S:pbd_safe] [INIT] --&amp;Init|[$Init.Text] --=EctorInit|[$Init] - .001 --~|turnorder;replacetoken;[*S:t-id];[$Init.Total] --~|turnorder;replacetoken;[*T:t-id];[$EctorInit.Total] --@forselected(*)| {*&amp; template:simple} {{rname=INITIATIVE}*} {{mod=[*S:initiative_bonus]}*} {{r1=[[ [$Init.Total] [*[&amp;Init]*] ]*]}*} {{normal=1}*} {{charname=[*S:character_name]}*} {^&amp; select @(Kimmuriel|token_id)} {*&amp;simple*} {*&amp;log*} }} This gets me the mouse over information I need correctly, but now the value has a yellow highlight. For comparison: this PC uses the standard initiative function built into the character sheet: w/o advantage this is the PC with the follower whose macro I'm writing (roll is highlighted, which I don't want) this PC also uses the built-in initiative roller, and has advantage on the roll. Although it does appear that the font size issue may be resolved?
1623879182

Edited 1623879219
Kurt J.
Pro
API Scripter
Mongo said: Greetings, I have been using Power Cards for Years now and many Table that I have made that are something like the following. !power {{ --name|@{selected|token_name}’s Loot! --Looting:|@{selected|character_name} rolls a [[ [$R] 1d100]] to loot the body. -- ?? $R == 1 ?? | [[2D6]] Platinum coins -- ?? $R == 2 ?? | [[8D6]] Gold coins -- ?? $R == 3 ?? | White Marble Chess Piece (Queen) -- ?? $R == 4 ?? | [[1D10]] Potions of Health -- ?? $R == 5 ?? | Brest Plate +2 Resist Psychic -- ?? $R == 6 ?? | [[1D6]] Flask of Alchemist's fire -- ?? $R == 7 ?? | Adamantine Greataxe -- ?? $R == 8 ?? | 1 gallon of grog (4 sp) -- ?? $R == 9 ?? | Sword and Dagger -- ?? $R == 10 ?? | [[2D6]] Gems worth [[1D6*10]] gold each! -- ?? $R == 89 ?? | An iron Ingot [[4D4]] lbs. -- ?? $R == 90 ?? | Fancy pocket watch with a fish face on the plate cover -- ?? $R == 91 ?? | [[3D6]] small black coins of unknown origin -- ?? $R == 92 ?? | Handy Haversack -- ?? $R == 93 ?? | Book – Almonds’ and Berries – The love of a druid -- ?? $R == 94 ?? | Sword of First Strike -- ?? $R == 95 ?? | Gold and Ivory Dice -- ?? $R == 96 ?? | Drum -- ?? $R == 97 ?? | Everbright Lantern -- ?? $R == 98 ?? | Gloves of Missile Snaring -- ?? $R == 99 ?? | It’s a Trap – (Darts), you take [[9D9]] piercing Damage! -- ?? $R == 100 ?? | WOW ! make [[2D10]] more picks and keep them all. }} I would love to switch over to scrptcards and would like to know how I could go about doing all the rolls and use the new formating? I have not been a programer for many many years and have fallen to simpler things now. Any and all advice would be helpful. Thank you all for your time. There are many ways you could approach this. The most direct conversion of what you have above would be: !script {{ --#title|@{selected|token_name}’s Loot! --=R|1d100 --+Looting:|@{selected|character_name} rolls a [$R] to loot the body. --&amp;L| --?[$R] -eq 1|&amp;L;[[2D6]] Platinum coins --?[$R] -eq 2|&amp;L;[[8D6]] Gold coins --?[$R] -eq 3|&amp;L;White Marble Chess Piece (Queen) --?[$R] -eq 4|&amp;L;[[1D10]] Potions of Health --?[$R] -eq 5|&amp;L;Brest Plate +2 Resist Psychic --?[$R] -eq 6|&amp;L;[[1D6]] Flask of Alchemist's fire --?[$R] -eq 7|&amp;L;Adamantine Greataxe --?[$R] -eq 8|&amp;L;1 gallon of grog (4 sp) --?[$R] -eq 9|&amp;L;Sword and Dagger --?[$R] -eq 10|&amp;L;[[2D6]] Gems worth [[1D6*10]] gold each! --?[$R] -eq 89|&amp;L;An iron Ingot [[4D4]] lbs. --?[$R] -eq 90|&amp;L;Fancy pocket watch with a fish face on the plate cover --?[$R] -eq 91|&amp;L;[[3D6]] small black coins of unknown origin --?[$R] -eq 92|&amp;L;Handy Haversack --?[$R] -eq 93|&amp;L;Book – Almonds’ and Berries – The love of a druid --?[$R] -eq 94|&amp;L; Sword of First Strike --?[$R] -eq 95|&amp;L; Gold and Ivory Dice --?[$R] -eq 96|&amp;L; Drum --?[$R] -eq 97|&amp;L; Everbright Lantern --?[$R] -eq 98|&amp;L; Gloves of Missile Snaring --?[$R] -eq 99|&amp;L; It’s a Trap – (Darts), you take [[9D9]] piercing Damage! --?[$R] -eq 100|&amp;L; WOW ! make [[2D10]] more picks and keep them all. --+|[&amp;L] }} However, that doesn't really take advantage of any of ScriptCards features. Here is a re-written version that takes the 100 roll into account. It uses an array with an initial value of "nothing" and adds rolled items to it. If an item was rolled, the "nothing" is removed: !script {{ --#title|@{selected|token_name}’s Loot! --~|array;define;loot;nothing --=RollCount|1 --:Reroll| --&gt;RollForLoot| --=RollCount|[$RollCount.Total] - 1 --?[$RollCount] -gt 0|Reroll --/|If there is more than one item in the loot array, remove the first (NOTHING) item. --~length|array;getlength;loot --?[&amp;length] -gt 1|[ --~|array;removeat;loot;0 --]| --/|Display the loot --+@{selected|token_name} finds...| --~length|array;getlength;loot --%lcount|0;[&amp;length] --+|[@loot([&amp;lcount])] --%| --X| --:RollForLoot| --=R|1d100 --+Looting:|@{selected|character_name} rolls a [$R] to loot the body. --&amp;L| --?[$R] -eq 1|&amp;L;[[2D6]] Platinum coins --?[$R] -eq 2|&amp;L;[[8D6]] Gold coins --?[$R] -eq 3|&amp;L;White Marble Chess Piece (Queen) --?[$R] -eq 4|&amp;L;[[1D10]] Potions of Health --?[$R] -eq 5|&amp;L;Brest Plate +2 Resist Psychic --?[$R] -eq 6|&amp;L;[[1D6]] Flask of Alchemist's fire --?[$R] -eq 7|&amp;L;Adamantine Greataxe --?[$R] -eq 8|&amp;L;1 gallon of grog (4 sp) --?[$R] -eq 9|&amp;L;Sword and Dagger --?[$R] -eq 10|&amp;L;[[2D6]] Gems worth [[1D6*10]] gold each! --?[$R] -eq 89|&amp;L;An iron Ingot [[4D4]] lbs. --?[$R] -eq 90|&amp;L;Fancy pocket watch with a fish face on the plate cover --?[$R] -eq 91|&amp;L;[[3D6]] small black coins of unknown origin --?[$R] -eq 92|&amp;L;Handy Haversack --?[$R] -eq 93|&amp;L;Book – Almonds’ and Berries – The love of a druid --?[$R] -eq 94|&amp;L; Sword of First Strike --?[$R] -eq 95|&amp;L; Gold and Ivory Dice --?[$R] -eq 96|&amp;L; Drum --?[$R] -eq 97|&amp;L; Everbright Lantern --?[$R] -eq 98|&amp;L; Gloves of Missile Snaring --?[$R] -eq 99|&amp;L; It’s a Trap – (Darts), you take [[9D9]] piercing Damage! --?[$R] -eq 100|[ --=Bonus|2d10 --=RollCount|[$RollCount.Total] + [$Bonus.Total] --]| --?"X[&amp;L]X" -ne "XX"|[ --~|array;add;loot;[&amp;L] --]| --&lt;| }} I would actually go further on this because it does have the issue that all of the "sub rolls" (like 9d9 piercing damage) will be the same if the 100 result rolls another item multiple times (ie, if you roll 100 and then two of the rerolls are 1's, you end up with the same number of platinum coins twice since that number will be preserved from the inline roll from chat). This could be improved by doing something like this: --?[$R] -eq 1|[ --=Calc|2d6 --&amp;L|[$Calc] Platinum coins --]| and similar for each line that contains a sub roll. This is similar to the handling of the 100 result above, where we break out and roll 2d10 the "ScriptCards way" :)
Another option is to stuff all of this into roll tables which you can easily modify and manage over time and then build a scriptcards menu system to select items from your roll tables.&nbsp; I've got dozens and dozens of random tables I've collected over the years (names, settings, npcs, treasures, scents, plots, quirks, ...) and am considering using the Arron's TableImportExport script to easily build them out in roll20, then using scriptcards, call on them as needed.&nbsp;&nbsp;
Kurt J. said: Mongo said: Greetings, I have been using Power Cards for Years now and many Table that I have made that are something like the following. !power {{ --name|@{selected|token_name}’s Loot! --Looting:|@{selected|character_name} rolls a [[ [$R] 1d100]] to loot the body. -- ?? $R == 1 ?? | [[2D6]] Platinum coins -- ?? $R == 2 ?? | [[8D6]] Gold coins -- ?? $R == 3 ?? | White Marble Chess Piece (Queen) -- ?? $R == 4 ?? | [[1D10]] Potions of Health -- ?? $R == 5 ?? | Brest Plate +2 Resist Psychic -- ?? $R == 6 ?? | [[1D6]] Flask of Alchemist's fire -- ?? $R == 7 ?? | Adamantine Greataxe -- ?? $R == 8 ?? | 1 gallon of grog (4 sp) -- ?? $R == 9 ?? | Sword and Dagger -- ?? $R == 10 ?? | [[2D6]] Gems worth [[1D6*10]] gold each! -- ?? $R == 89 ?? | An iron Ingot [[4D4]] lbs. -- ?? $R == 90 ?? | Fancy pocket watch with a fish face on the plate cover -- ?? $R == 91 ?? | [[3D6]] small black coins of unknown origin -- ?? $R == 92 ?? | Handy Haversack -- ?? $R == 93 ?? | Book – Almonds’ and Berries – The love of a druid -- ?? $R == 94 ?? | Sword of First Strike -- ?? $R == 95 ?? | Gold and Ivory Dice -- ?? $R == 96 ?? | Drum -- ?? $R == 97 ?? | Everbright Lantern -- ?? $R == 98 ?? | Gloves of Missile Snaring -- ?? $R == 99 ?? | It’s a Trap – (Darts), you take [[9D9]] piercing Damage! -- ?? $R == 100 ?? | WOW ! make [[2D10]] more picks and keep them all. }} I would love to switch over to scrptcards and would like to know how I could go about doing all the rolls and use the new formating? I have not been a programer for many many years and have fallen to simpler things now. Any and all advice would be helpful. Thank you all for your time. There are many ways you could approach this. The most direct conversion of what you have above would be: !script {{ --#title|@{selected|token_name}’s Loot! --=R|1d100 --+Looting:|@{selected|character_name} rolls a [$R] to loot the body. --&amp;L| --?[$R] -eq 1|&amp;L;[[2D6]] Platinum coins --?[$R] -eq 2|&amp;L;[[8D6]] Gold coins --?[$R] -eq 3|&amp;L;White Marble Chess Piece (Queen) --?[$R] -eq 4|&amp;L;[[1D10]] Potions of Health --?[$R] -eq 5|&amp;L;Brest Plate +2 Resist Psychic --?[$R] -eq 6|&amp;L;[[1D6]] Flask of Alchemist's fire --?[$R] -eq 7|&amp;L;Adamantine Greataxe --?[$R] -eq 8|&amp;L;1 gallon of grog (4 sp) --?[$R] -eq 9|&amp;L;Sword and Dagger --?[$R] -eq 10|&amp;L;[[2D6]] Gems worth [[1D6*10]] gold each! --?[$R] -eq 89|&amp;L;An iron Ingot [[4D4]] lbs. --?[$R] -eq 90|&amp;L;Fancy pocket watch with a fish face on the plate cover --?[$R] -eq 91|&amp;L;[[3D6]] small black coins of unknown origin --?[$R] -eq 92|&amp;L;Handy Haversack --?[$R] -eq 93|&amp;L;Book – Almonds’ and Berries – The love of a druid --?[$R] -eq 94|&amp;L; Sword of First Strike --?[$R] -eq 95|&amp;L; Gold and Ivory Dice --?[$R] -eq 96|&amp;L; Drum --?[$R] -eq 97|&amp;L; Everbright Lantern --?[$R] -eq 98|&amp;L; Gloves of Missile Snaring --?[$R] -eq 99|&amp;L; It’s a Trap – (Darts), you take [[9D9]] piercing Damage! --?[$R] -eq 100|&amp;L; WOW ! make [[2D10]] more picks and keep them all. --+|[&amp;L] }} However, that doesn't really take advantage of any of ScriptCards features. Here is a re-written version that takes the 100 roll into account. It uses an array with an initial value of "nothing" and adds rolled items to it. If an item was rolled, the "nothing" is removed: !script {{ --#title|@{selected|token_name}’s Loot! --~|array;define;loot;nothing --=RollCount|1 --:Reroll| --&gt;RollForLoot| --=RollCount|[$RollCount.Total] - 1 --?[$RollCount] -gt 0|Reroll --/|If there is more than one item in the loot array, remove the first (NOTHING) item. --~length|array;getlength;loot --?[&amp;length] -gt 1|[ --~|array;removeat;loot;0 --]| --/|Display the loot --+@{selected|token_name} finds...| --~length|array;getlength;loot --%lcount|0;[&amp;length] --+|[@loot([&amp;lcount])] --%| --X| --:RollForLoot| --=R|1d100 --+Looting:|@{selected|character_name} rolls a [$R] to loot the body. --&amp;L| --?[$R] -eq 1|&amp;L;[[2D6]] Platinum coins --?[$R] -eq 2|&amp;L;[[8D6]] Gold coins --?[$R] -eq 3|&amp;L;White Marble Chess Piece (Queen) --?[$R] -eq 4|&amp;L;[[1D10]] Potions of Health --?[$R] -eq 5|&amp;L;Brest Plate +2 Resist Psychic --?[$R] -eq 6|&amp;L;[[1D6]] Flask of Alchemist's fire --?[$R] -eq 7|&amp;L;Adamantine Greataxe --?[$R] -eq 8|&amp;L;1 gallon of grog (4 sp) --?[$R] -eq 9|&amp;L;Sword and Dagger --?[$R] -eq 10|&amp;L;[[2D6]] Gems worth [[1D6*10]] gold each! --?[$R] -eq 89|&amp;L;An iron Ingot [[4D4]] lbs. --?[$R] -eq 90|&amp;L;Fancy pocket watch with a fish face on the plate cover --?[$R] -eq 91|&amp;L;[[3D6]] small black coins of unknown origin --?[$R] -eq 92|&amp;L;Handy Haversack --?[$R] -eq 93|&amp;L;Book – Almonds’ and Berries – The love of a druid --?[$R] -eq 94|&amp;L; Sword of First Strike --?[$R] -eq 95|&amp;L; Gold and Ivory Dice --?[$R] -eq 96|&amp;L; Drum --?[$R] -eq 97|&amp;L; Everbright Lantern --?[$R] -eq 98|&amp;L; Gloves of Missile Snaring --?[$R] -eq 99|&amp;L; It’s a Trap – (Darts), you take [[9D9]] piercing Damage! --?[$R] -eq 100|[ --=Bonus|2d10 --=RollCount|[$RollCount.Total] + [$Bonus.Total] --]| --?"X[&amp;L]X" -ne "XX"|[ --~|array;add;loot;[&amp;L] --]| --&lt;| }} I would actually go further on this because it does have the issue that all of the "sub rolls" (like 9d9 piercing damage) will be the same if the 100 result rolls another item multiple times (ie, if you roll 100 and then two of the rerolls are 1's, you end up with the same number of platinum coins twice since that number will be preserved from the inline roll from chat). This could be improved by doing something like this: --?[$R] -eq 1|[ --=Calc|2d6 --&amp;L|[$Calc] Platinum coins --]| and similar for each line that contains a sub roll. This is similar to the handling of the 100 result above, where we break out and roll 2d10 the "ScriptCards way" :) @Kurt J.&nbsp; Thank you so much for all the ideas. I have been looking at Script cards for a couple weeks now and have been playing with different thigs to do. Kind of hit the point where I was trying so many different things that nothing was working. I again Thank you and Will M. for all the great advice that you guys give. i will be happy to post up what I wind up doing. i would love to talk to Will M. about how to do some simple table that the script could just call on. I have Encounters that I edit every week for the level of the players and their location. I take all this very seriously and appreciate that you guys help us newbes out.
1623892808
timmaugh
Pro
API Scripter
You can also look at Muler as a way to handle static table retrieval. The Mule is stored on a character, so it's easy to port from game to game. It can handle ranges of keys (ie, 10-13, 14-16, &gt;17). And as a meta script, it can work in other scripts (or even basic chat messages).
Learned something new while working on the dependent turn order script above: @{tracker|&lt;token name&gt;} This retrieves the initiative value of &lt;token name&gt;: who knew! @Kurt: could you add functionality for retrieving information from the tracker rather than merely modifying it? Something like: --~RollVar|turnorder;retrievecommand;&lt;token name&gt;
timmaugh said: You can also look at Muler as a way to handle static table retrieval. The Mule is stored on a character, so it's easy to port from game to game. It can handle ranges of keys (ie, 10-13, 14-16, &gt;17). And as a meta script, it can work in other scripts (or even basic chat messages). BTW: I was reading the Muler thread and the setup was unclear. Do the mules go into abilities or attributes? Like, if I just want to have the whole content of the mule dropped into chat for whatever reason, would I use %{character name|mule name} or @{character name|mule name}?
1623895419

Edited 1623895431
David M.
Pro
API Scripter
Mongo, rolling on a table is pretty simple. You assign a value of [T#tableName] to a roll variable, then refer to either the item text with [$tableName.tableEntryText] or the item image with [$tableName. tableEntryImgURL ]. Here is a simple example that rolls on two tables (MaleNames, and Surnames) then outputs the full name to the chat: !script {{ &nbsp; --=firstName|[T#MaleNames] &nbsp; --=surname|[T#Surnames] &nbsp; --+Full Name|[$firstName.tableEntryText] [$surname.tableEntryText] }}
I am having an issue getting the resource amount using the following script.&nbsp; This is just a test script script to see what is happening for testing purposes. !scriptcards{{ &nbsp; --#sourceToken|@{selected|token_id} &nbsp; --&amp;ResourceUsed|repeating_resource_$0_resource_right &nbsp; --=resources|@{selected|repeating_resource_$0_resource_right} &nbsp;--=resource|[*S:[&amp;ResourceUsed]] &nbsp; --+resources|[$resources] &nbsp; --+resource|[$resource] }} I believe these should return the same number of 1, but they return the 0 for resources and 1 for resource.
David M. said: Mongo, rolling on a table is pretty simple. You assign a value of [T#tableName] to a roll variable, then refer to either the item text with [$tableName.tableEntryText] or the item image with [$tableName. tableEntryImgURL ]. Here is a simple example that rolls on two tables (MaleNames, and Surnames) then outputs the full name to the chat: !script {{ &nbsp; --=firstName|[T#MaleNames] &nbsp; --=surname|[T#Surnames] &nbsp; --+Full Name|[$firstName.tableEntryText] [$surname.tableEntryText] }} @David M. Beautiful script sir. I learn more every day. Thank you
1623900922
timmaugh
Pro
API Scripter
Colin C. said: timmaugh said: You can also look at Muler as a way to handle static table retrieval. The Mule is stored on a character, so it's easy to port from game to game. It can handle ranges of keys (ie, 10-13, 14-16, &gt;17). And as a meta script, it can work in other scripts (or even basic chat messages). BTW: I was reading the Muler thread and the setup was unclear. Do the mules go into abilities or attributes? Like, if I just want to have the whole content of the mule dropped into chat for whatever reason, would I use %{character name|mule name} or @{character name|mule name}? They are abilities. Hit me up on that thread if you want more information, just so we don't pollute this thread too much.
1623957945

Edited 1623968606
Kurt J.
Pro
API Scripter
Colin C. said: Learned something new while working on the dependent turn order script above: @{tracker|&lt;token name&gt;} This retrieves the initiative value of &lt;token name&gt;: who knew! @Kurt: could you add functionality for retrieving information from the tracker rather than merely modifying it? Something like: --~RollVar|turnorder;retrievecommand;&lt;token name&gt; This is done and will be included in the next release as "turnorder;findtoken;token-id", along with "turnorder;getcurrentactor" to get the currently active turn. Also, it returns a string var, as the initiative value CAN contain non-numeric characters. Token name is a little trickier, since that isn't what is stored in the turnorder tracker, so I would need to find an active token with that name and match it, but I'll ponder some options.
Greetings, Has anyone worked out a simple Initiative Tracker like this one from Power Cards? !power {{ --tokenid|@{selected|token_id} --emote|@{selected|character_name} readies --format|default --name|Initiative --!Initiative|~C@{selected|character_name}: [[ [nh|trkr] 1d20 + @{selected|dexterity_mod} ]]~C }} Asking for a friend&nbsp;
1623968556
Kurt J.
Pro
API Scripter
Mongo said: Greetings, Has anyone worked out a simple Initiative Tracker like this one from Power Cards? !power {{ --tokenid|@{selected|token_id} --emote|@{selected|character_name} readies --format|default --name|Initiative --!Initiative|~C@{selected|character_name}: [[ [nh|trkr] 1d20 + @{selected|dexterity_mod} ]]~C }} Asking for a friend&nbsp; Again, the "many ways" caveat :) Here is an example translating the PowerCard above to a Script. I included comments (which start with --/|) to explain what each line is doing. They are ignored by the parser and can be removed to shorten things up. !script {{ --/|Setting the "sourcetoken" parameter does several things, including putting the token's graphic in the left side of the emote area. --#sourcetoken|@{selected|token_id} --/|Setting the "emotetext" setting is the same as the PowerCards emote line --#emotetext|@{selected|token_name} readies --/|The "title" setting is the equivalent of "name" in PowerCards and sets the title of the card --#title|Initiative --/|All rolling in ScriptCards is done on "=" lines and assigned to variables that can be used and reused anywhere in the script. Here, we roll 1d20 and add the token's initiative_bonus value. This is preferrable to using the dexterity modifier because some characters will have other bonuses that impact their initiative. --=InitRoll|1d20 + @{selected|initiative_bonus} --/|Manipulation of the turn tracker is done through the function (~) statement with the turnorder command. Here we use the replacetoken subcommand to set the token's initiative in the tracker to the value we rolled. If we used "addtoken" we could potentially add multiple entries for the same token. --~|turnorder;replacetoken;@{selected|token_id};[$InitRoll] --/|Unlike PowerCards, tags are not always required and don't need to be unique. Here, we omit the tag from the output line and use [c]...[/c] to center the ouptut text --+|[c]@{selected|token_name}: [$InitRoll.Total][/c] }}