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 with ScriptCard script Set Monster HP

Hi all, I have just tried to use the following script to randomise my NPC's HP but it doesn't seem to implement the token-mod set bar1 part. If I input the token mod code into chat myself it works but it doesn't through the macro script. This is the code I am using&nbsp; <a href="https://app.roll20.net/forum/post/10000297/scritpcard-api-working-and-sharing/?pageforid=10419857#post-10419857" rel="nofollow">https://app.roll20.net/forum/post/10000297/scritpcard-api-working-and-sharing/?pageforid=10419857#post-10419857</a> !script {{ --/|Script Name : Set Monster HP --/|Version : 1.0 --/|Requires SC : 1.4.0+ --/|Author : Will M. --/|Description : Utility function that resets all selected NPC hps based on the HPFormula (with a twist) --/| Twist - It allows for the following HP calcs: --/| Default - Standard static HP based on HPFormula (no randomness) --/| Random - Uses the HPFormula to derive HP --/| Random High (x Rolls) - Will take the highest value of x(2,5, or 10) rolls. --/| Random Low (x Rolls) - Will take the lowest value of x(2,5, or 10) rolls. --/| --/| Adder - A value (+/-) to add to the final result --#title|Set Monster HP --#reentrant|SetMonsterHP --#titleCardBackground|#932729 --#whisper|self --#oddRowBackground|#FFFFFF --#evenRowBackground|#FFFFFF --#buttonbackground|#FFFFFF --#buttontextcolor|#0905f2 --#buttonbordercolor|#FFFFFF --#bodyFontSize|11px --#debug|1 --/| set to bar2_value or bar3_value if you use one of those two for tracking HP --&amp;HPField|bar1_value --/| Modes 0-Default,1-Random,2-Random (High), 3 Random (Low) --&amp;Mode|0 --&amp;Adder|0 --&amp;HP_ROLL_COUNT|0 --&amp;Mode|?{HP Set Mode?|Default,0|Random,1|Random High(2 Rolls),2.2|Random High(5 Rolls),2.5|Random High(10 Rolls),2.10|Random Low(2 Rolls),3.2|Random Low(5 Rolls),3.5|Random Low(10 Rolls),3.10} --&amp;Adder|?{Additional Adder|0} --+Adder|[&amp;Adder] --?[&amp;Mode] -eq 2.2|[ --&amp;Mode|2 --&amp;HP_ROLL_COUNT|2 --]| --?[&amp;Mode] -eq 2.5|[ --&amp;Mode|2 --&amp;HP_ROLL_COUNT|5 --]| --?[&amp;Mode] -eq 2.10| [ --&amp;Mode|2 --&amp;HP_ROLL_COUNT|10 --]| --?[&amp;Mode] -eq 3.2|[ --&amp;Mode|3 --&amp;HP_ROLL_COUNT|2 --]| --?[&amp;Mode] -eq 3.5|[ --&amp;Mode|3 --&amp;HP_ROLL_COUNT|5 --]| --?[&amp;Mode] -eq 3.10|[ --&amp;Mode|3 --&amp;HP_ROLL_COUNT|10 --]| --=i|0 --/| !token-mod --set bar1|[[@{selected|npc_hpformula}]] --/| For each selected Token --~Token|getselected --+TokenCount|[&amp;TokenCount] --+Mode|[&amp;Mode] --:MAIN_LOOP_TOP| --?[$i.Raw] -eq [&amp;TokenCount]|MAIN_LOOP_EXIT --=i|[$i] + 1 --/| If it is an NPC token associated with a monster sheet then proceed --?[*[&amp;Token[$i.Raw]]:npc] -ne 1|MAIN_LOOP_TOP --?"[*[&amp;Token[$i.Raw]]:t-represents]" -ninc "-"|MAIN_LOOP_TOP --/| Get the npc_hpformula --&amp;CharId|[*[&amp;Token[$i.Raw]]:t-represents] --&amp;HPFormula|[*[&amp;CharId]:npc_hpformula] --/| Based on Mode - determine HP --C[&amp;Mode]|0:MODE_DEFAULT|1:MODE_RANDOM|2:MODE_RAND_HIGH|3:MODE_RAND_LOW --/|Case 0 - Default --:MODE_DEFAULT| --=HP|[*[&amp;CharId]:hp^] + [&amp;Adder] --^END_CASE| --/|Case 1 - Random --:MODE_RANDOM| --=HP|[&amp;HPFormula] + [&amp;Adder] --^END_CASE| --/|Case 2 - Random - High --:MODE_RAND_HIGH| --&gt;HP_RAND_HIGH| --^END_CASE| --/|Case 3 - Random - Low --:MODE_RAND_LOW| --&gt;HP_RAND_LOW| --^END_CASE| --:END_CASE| --+[$i.Raw].|[*[&amp;Token[$i.Raw]]:t-name]: ([&amp;HPFormula]) + [&amp;Adder] [$HP] --@token-mod|_set [&amp;HPField]|[$HP.Raw] _ids [&amp;Token[$i.Raw]] _ignore-selected --/|Apply Calculated HP --/| Next token --^MAIN_LOOP_TOP| --:MAIN_LOOP_EXIT| --+Done!| --X| --:HP_RAND_HIGH| --=HP|-500 --=j|0 --:HPRH_LOOP_TOP| --?[$j.Raw] -eq [&amp;HP_ROLL_COUNT]|HPRH_LOOP_END --=x|[&amp;HPFormula] + [&amp;Adder] --+&amp;nbsp;&amp;nbsp;RHigh(x / HP)|[$x] / [$HP] --~HP|math;max;[$HP];[$x] --=j|[$j] + 1 --^HPRH_LOOP_TOP| --:HPRH_LOOP_END| --&lt;| --:HP_RAND_LOW| --=HP|500 --=j|0 --:HPRL_LOOP_TOP| --?[$j.Raw] -eq [&amp;HP_ROLL_COUNT]|HPRL_LOOP_END --=x|[&amp;HPFormula] + [&amp;Adder] --+&amp;nbsp;&amp;nbsp;RLow(x / HP)|[$x] / [$HP] --~HP|math;min;[$HP];[$x] --=j|[$j] + 1 --^HPRL_LOOP_TOP| --:HPRL_LOOP_END| --&lt;| }}
1645717360
David M.
Pro
API Scripter
First thing I would try is outputting the dynamically generated syntax of the token-mod call. So instead of this: --@token-mod|_set [&amp;HPField]|[$HP.Raw] _ids [&amp;Token[$i.Raw]] _ignore-selected Temporarily use something like this: --+Generated syntax|!token-mod _set [&amp;HPField]|[$HP.Raw] _ids [&amp;Token[$i.Raw]] _ignore-selected Then you can copy the dynamically-generated syntax from the chat window into another test macro to see if it works or if the syntax is malformed. Note you will have to replace the underscores with double dashes (--) prior to testing.
1645726028

Edited 1645726857
Thank you for your reply, unfortunatly I don't really understand what you mean. where would I get the dynamically generated syntax? David M. said: First thing I would try is outputting the dynamically generated syntax of the token-mod call. So instead of this: --@token-mod|_set [&amp;HPField]|[$HP.Raw] _ids [&amp;Token[$i.Raw]] _ignore-selected Temporarily use something like this: --+Generated syntax|!token-mod _set [&amp;HPField]|[$HP.Raw] _ids [&amp;Token[$i.Raw]] _ignore-selected Then you can copy the dynamically-generated syntax from the chat window into another test macro to see if it works or if the syntax is malformed. Note you will have to replace the underscores with double dashes (--) prior to testing. If it helps, my console log is as follows "Setting parameter debug to value 1" "Line Counter: 24, Tag:/, Content:set to bar2_value or bar3_value if you use one of those two for tracking HP" "Line Counter: 25, Tag:&amp;HPField, Content:bar1_value" "Line Counter: 26, Tag:/, Content:Modes 0-Default,1-Random,2-Random (High), 3 Random (Low)" "Line Counter: 27, Tag:&amp;Mode, Content:0" "Line Counter: 28, Tag:&amp;Adder, Content:0" "Line Counter: 29, Tag:&amp;HP_ROLL_COUNT, Content:0" "Line Counter: 30, Tag:&amp;Mode, Content:1" "Line Counter: 31, Tag:&amp;Adder, Content:0" "ContentIn: [&amp;Adder] Match: [&amp;Adder], vName: Adder, replacement 0" "Line Counter: 32, Tag:+Adder, Content:0" "ContentIn: ?[&amp;Mode] -eq 2.2 Match: [&amp;Mode], vName: Mode, replacement 1" "Line Counter: 33, Tag:?1 -eq 2.2, Content:[" "Condition 1 -eq 2.2 evaluation result: false" "ContentIn: ?[&amp;Mode] -eq 2.5 Match: [&amp;Mode], vName: Mode, replacement 1" "Line Counter: 37, Tag:?1 -eq 2.5, Content:[" "Condition 1 -eq 2.5 evaluation result: false" "ContentIn: ?[&amp;Mode] -eq 2.10 Match: [&amp;Mode], vName: Mode, replacement 1" "Line Counter: 41, Tag:?1 -eq 2.10, Content:[" "Condition 1 -eq 2.10 evaluation result: false" "ContentIn: ?[&amp;Mode] -eq 3.2 Match: [&amp;Mode], vName: Mode, replacement 1" "Line Counter: 45, Tag:?1 -eq 3.2, Content:[" "Condition 1 -eq 3.2 evaluation result: false" "ContentIn: ?[&amp;Mode] -eq 3.5 Match: [&amp;Mode], vName: Mode, replacement 1" "Line Counter: 49, Tag:?1 -eq 3.5, Content:[" "Condition 1 -eq 3.5 evaluation result: false" "ContentIn: ?[&amp;Mode] -eq 3.10 Match: [&amp;Mode], vName: Mode, replacement 1" "Line Counter: 53, Tag:?1 -eq 3.10, Content:[" "Condition 1 -eq 3.10 evaluation result: false" "Line Counter: 57, Tag:=i, Content:0" "Line Counter: 58, Tag:/, Content:!token-mod" "Line Counter: 59, Tag:set bar1, Content:11" "Line Counter: 60, Tag:/, Content:For each selected Token" "Line Counter: 61, Tag:~Token, Content:getselected" "ContentIn: [&amp;TokenCount] Match: [&amp;TokenCount], vName: TokenCount, replacement 1" "Line Counter: 62, Tag:+TokenCount, Content:1" "ContentIn: [&amp;Mode] Match: [&amp;Mode], vName: Mode, replacement 1" "Line Counter: 63, Tag:+Mode, Content:1" "Line Counter: 64, Tag::MAIN_LOOP_TOP, Content:" "ContentIn: ?[$i.Raw] -eq [&amp;TokenCount] Match: [$i.Raw], vName: i, vSuffix: Raw, replacement 0" "ContentIn: ?0 -eq [&amp;TokenCount] Match: [&amp;TokenCount], vName: TokenCount, replacement 1" "Line Counter: 65, Tag:?0 -eq 1, Content:MAIN_LOOP_EXIT" "Condition 0 -eq 1 evaluation result: false" "ContentIn: [$i] + 1 Match: [$i], vName: i, vSuffix: Total, replacement 0" "Line Counter: 66, Tag:=i, Content:0 + 1" "Line Counter: 67, Tag:/, Content:If it is an NPC token associated with a monster sheet then proceed" "ContentIn: ?[*[&amp;Token[$i.Raw]]:npc] -ne 1 Match: [$i.Raw], vName: i, vSuffix: Raw, replacement 1" "ContentIn: ?[*[&amp;Token1]:npc] -ne 1 Match: [&amp;Token1], vName: Token1, replacement -KI58Rne3BAYb1fW5C-A" "Line Counter: 68, Tag:?1 -ne 1, Content:MAIN_LOOP_TOP" "Condition 1 -ne 1 evaluation result: false" "ContentIn: ?\"[*[&amp;Token[$i.Raw]]:t-represents]\" -ninc \"-\" Match: [$i.Raw], vName: i, vSuffix: Raw, replacement 1" "ContentIn: ?\"[*[&amp;Token1]:t-represents]\" -ninc \"-\" Match: [&amp;Token1], vName: Token1, replacement -KI58Rne3BAYb1fW5C-A" "Line Counter: 69, Tag:?\"-JvzOZQmWHzGfufDsoXC\" -ninc \"-\", Content:MAIN_LOOP_TOP" "Condition \"-JvzOZQmWHzGfufDsoXC\" -ninc \"-\" evaluation result: false" "Line Counter: 70, Tag:/, Content:Get the npc_hpformula" "ContentIn: [*[&amp;Token[$i.Raw]]:t-represents] Match: [$i.Raw], vName: i, vSuffix: Raw, replacement 1" "ContentIn: [*[&amp;Token1]:t-represents] Match: [&amp;Token1], vName: Token1, replacement -KI58Rne3BAYb1fW5C-A" "Line Counter: 71, Tag:&amp;CharId, Content:-JvzOZQmWHzGfufDsoXC" "ContentIn: [*[&amp;CharId]:npc_hpformula] Match: [&amp;CharId], vName: CharId, replacement -JvzOZQmWHzGfufDsoXC" "Line Counter: 72, Tag:&amp;HPFormula, Content:2d6" "Line Counter: 73, Tag:/, Content:Based on Mode - determine HP" "ContentIn: C[&amp;Mode] Match: [&amp;Mode], vName: Mode, replacement 1" "Line Counter: 74, Tag:C1, Content:0:MODE_DEFAULT|1:MODE_RANDOM|2:MODE_RAND_HIGH|3:MODE_RAND_LOW" "ContentIn: [&amp;HPFormula] + [&amp;Adder] Match: [&amp;HPFormula], vName: HPFormula, replacement 2d6" "ContentIn: 2d6 + [&amp;Adder] Match: [&amp;Adder], vName: Adder, replacement 0" "Line Counter: 81, Tag:=HP, Content:2d6 + 0" "Line Counter: 82, Tag:^END_CASE, Content:" "ContentIn: +[$i.Raw]. Match: [$i.Raw], vName: i, vSuffix: Raw, replacement 1" "ContentIn: [*[&amp;Token[$i.Raw]]:t-name]: ([&amp;HPFormula]) + [&amp;Adder] [$HP] Match: [$i.Raw], vName: i, vSuffix: Raw, replacement 1" "ContentIn: [*[&amp;Token1]:t-name]: ([&amp;HPFormula]) + [&amp;Adder] [$HP] Match: [&amp;Token1], vName: Token1, replacement -KI58Rne3BAYb1fW5C-A" "ContentIn: Goblin: ([&amp;HPFormula]) + [&amp;Adder] [$HP] Match: [&amp;HPFormula], vName: HPFormula, replacement 2d6" "ContentIn: Goblin: (2d6) + [&amp;Adder] [$HP] Match: [&amp;Adder], vName: Adder, replacement 0" "ContentIn: Goblin: (2d6) + 0 [$HP] Match: [$HP], vName: HP, vSuffix: Total, replacement &lt;span style=' font-family: undefined; font-size: 1.2em; font-weight: normal; font-style: normal;&nbsp; text-align: center; font-size: 100%; display: inline-block; font-weight: bold; height: !{rollhilightlineheight}; min-width: 1.75em; margin-top: -1px; margin-bottom: 1px; padding: 0px 2px; border: 1px solid; border-radius: 3px; background-color: !{rollhilightcolorcrit}; border-color: #004400; color: #004400; ' class='showtip tipsy' title='Roll: 2d6 + 0&lt;br /&gt;&lt;br /&gt;Result: (5,6) + 0 '&gt;11&lt;/span&gt;" "Line Counter: 92, Tag:+1., Content:Goblin: (2d6) + 0 &lt;span style=' font-family: undefined; font-size: 1.2em; font-weight: normal; font-style: normal;&nbsp; text-align: center; font-size: 100%; display: inline-block; font-weight: bold; height: !{rollhilightlineheight}; min-width: 1.75em; margin-top: -1px; margin-bottom: 1px; padding: 0px 2px; border: 1px solid; border-radius: 3px; background-color: !{rollhilightcolorcrit}; border-color: #004400; color: #004400; ' class='showtip tipsy' title='Roll: 2d6 + 0&lt;br /&gt;&lt;br /&gt;Result: (5,6) + 0 '&gt;11&lt;/span&gt;" "ContentIn: _set [&amp;HPField]|[$HP.Raw] _ids [&amp;Token[$i.Raw]] _ignore-selected Match: [&amp;HPField], vName: HPField, replacement bar1_value" "ContentIn: _set bar1_value|[$HP.Raw] _ids [&amp;Token[$i.Raw]] _ignore-selected Match: [$HP.Raw], vName: HP, vSuffix: Raw, replacement 11" "ContentIn: _set bar1_value|11 _ids [&amp;Token[$i.Raw]] _ignore-selected Match: [$i.Raw], vName: i, vSuffix: Raw, replacement 1" "ContentIn: _set bar1_value|11 _ids [&amp;Token1] _ignore-selected Match: [&amp;Token1], vName: Token1, replacement -KI58Rne3BAYb1fW5C-A" "Line Counter: 93, Tag:@token-mod, Content:_set bar1_value|11 _ids -KI58Rne3BAYb1fW5C-A _ignore-selected" "ScriptCards: Making API call - !token-mod&nbsp; --set bar1_value|11 --ids -KI58Rne3BAYb1fW5C-A --ignore-selected" "Line Counter: 94, Tag:/, Content:Apply Calculated HP" "Line Counter: 95, Tag:/, Content:Next token" "Line Counter: 96, Tag:^MAIN_LOOP_TOP, Content:" "ContentIn: ?[$i.Raw] -eq [&amp;TokenCount] Match: [$i.Raw], vName: i, vSuffix: Raw, replacement 1" "ContentIn: ?1 -eq [&amp;TokenCount] Match: [&amp;TokenCount], vName: TokenCount, replacement 1" "Line Counter: 65, Tag:?1 -eq 1, Content:MAIN_LOOP_EXIT" "Condition 1 -eq 1 evaluation result: true" "Line Counter: 98, Tag:+Done!, Content:"
1645729762

Edited 1645729823
David M.
Pro
API Scripter
Sure, np. You are currently dynamically generating the token-mod syntax, meaning your scriptcard is rolling stuff and grabbing tokenids, then assembling token-mod syntax during run-time. ____________________________________ What I had suggested was (for testing purposes) take the macro you posted above and replace the line I pointed out with the replacement line I offered. So basically, instead of the scriptcard calling token-mod (and failing silently), it will instead print out the actual text of the token-mod call (that your scriptcard assembled) to your chat. That is an easy way to test that all of this (&nbsp; [&amp;HPField]|[$HP.Raw] _ids [&amp;Token[$i.Raw]] &nbsp; ) actually has the content you expect. Using this method, you then run your scriptcard, copy the resulting token-mod line from your scriptcard chat output, replace the underscores with "--", and paste it into a new macro to see if that token-mod syntax works as expected. I do this all the time when I have trouble farming out api calls from scriptcards. It will help point you in the right direction to where your problem lies.&nbsp; ___________________________________________ That being said, it looks like you already have that information from your debug output in your console log! So, instead of what I was just talking about above (lol), take this line in your console log: "ScriptCards: Making API call - !token-mod&nbsp; --set bar1_value|11 --ids -KI58Rne3BAYb1fW5C-A --ignore-selected" &nbsp; ...and paste that token mod syntax into a separate macro to see if it works. If I had to guess, you may not have the "players can use ids" setting enabled in the token-mod settings. This is found on your api page when you select the token-mod script. There is a checkbox. Hope that helps.
1645730252

Edited 1645730451
the macro with the following code worked !token-mod&nbsp; --set bar1_value|11 --ids -KI58Rne3BAYb1fW5C-A --ignore-selected" &nbsp; It changed the tokens bar 1 value to 11. And yes you are correct that the players can us ids was turned off. testing with it turned on now but currently I am the only person in the game as GM. edit: Turning on the players can use IDs seems to have solved the problem, thank you very much for your time.
Colin B. said: the macro with the following code worked !token-mod&nbsp; --set bar1_value|11 --ids -KI58Rne3BAYb1fW5C-A --ignore-selected" &nbsp; It changed the tokens bar 1 value to 11. And yes you are correct that the players can us ids was turned off. testing with it turned on now but currently I am the only person in the game as GM. edit: Turning on the players can use IDs seems to have solved the problem, thank you very much for your time. I don't think its a script problem, I think its a tokenmod problem.&nbsp; I currently have an almost identical problem with rolling hps with tokenmod for tokens that are also getting assigned to a sheet and having their bars linked.&nbsp; Unless Aaron wants to chime in with a command that works, the hp always override to the sheets prewritten values as the roll equation happens first and then theres a delay for the two sheet related actions tokenmod does.&nbsp; And since we can't run multiple tokenmod commands in macros due to the bug with sometimes them not all firing, makes the button not work reliably.&nbsp; The only way I can roll hitpoints for a token, and assign it is to leave the bar1 unlinked.&nbsp; Hopefully this helps /shrug
1645791718
David M.
Pro
API Scripter
I think Colin's macro is working now? (the edit from his last post)&nbsp; Problem was "players can use ids" was not checked.
David M. said: I think Colin's macro is working now? (the edit from his last post)&nbsp; Problem was "players can use ids" was not checked. Yes, that is the case. I have now moved onto the next script to give me a headache lol. Some experiments to come over the weekend then.