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

ScriptCards: Minor spell slot deduction macro help request

I'm new to ScripCards and have assembled the following to deduct a chosen spell slot from the Roll20 5e Character Sheet. It works but prints the Spell Slots Left twice: It might be obvious to another once they look at the code but I didn't see the problem. Does anyone know how to fix this? Much thanks!  :)) !script {{   --#title|Spell Slot Deduction     --=SpellLevel|?{Spell Slot Level?|1|2|3|4|5|6|7|8|9}   --#sourcetoken|@{selected|token_id}  -->GetAndCheckSlotInformation|  -->DeductSpellSlot|  --:GetAndCheckSlotInformation|   --=SlotLevel|[$SpellLevel]   --=SlotsTotal|[*S:lvl[$SlotLevel]_slots_total]    --=SlotsExpended|[*S:lvl[$SlotLevel]_slots_expended]   --?[$SlotsExpended.Total] -eq 0|NoSlotsLeft   --?[$SlotsExpended.Total] -gt [$SlotsTotal.Total]|NoSlotsLeft   --<|    --:DeductSpellSlot|   --=SlotsExpended|[$SlotsExpended] -1    --@setattr|_charid [*S:character_id] _lvl[$SlotLevel]_slots_expended|[$SlotsExpended] _silent  --=SlotsRemaining|[$SlotsTotal] - 1  --+|[c][b]Level [$SpellLevel.Total] Spell Slots Left: [/b][$SlotsExpended][/c]  --<|  --X|   --:NoSlotsLeft|   --+|[b][*S:character_name] has no level [$SlotLevel.Total] spell slots available.[/b]   --X|NoSlotsLeftStop }}
So in this case I think it might be best to go a simpler with the code and remove the labels and the branch calls with something like this. !script {{ --#title|Spell Slot Deduction --=SpellLevel|?{Spell Slot Level?|1|2|3|4|5|6|7|8|9} --#sourcetoken|@{selected|token_id} --=SlotLevel|[$SpellLevel] --=SlotsTotal|[*S:lvl[$SlotLevel]_slots_total] --=SlotsExpended|[*S:lvl[$SlotLevel]_slots_expended] --?[$SlotsExpended.Total] -eq 0|NoSlotsLeft --?[$SlotsExpended.Total] -gt [$SlotsTotal.Total]|NoSlotsLeft --=SlotsExpended|[$SlotsExpended] -1 --@setattr|_charid [*S:character_id] _lvl[$SlotLevel]_slots_expended|[$SlotsExpended] _silent --=SlotsRemaining|[$SlotsTotal] - 1 --+|[c][b]Level [$SpellLevel.Total] Spell Slots Left: [/b][$SlotsExpended][/c] --X| --:NoSlotsLeft| --+|[b][*S:character_name] has no level [$SlotLevel.Total] spell slots available.[/b] --X|NoSlotsLeftStop }} It's all the same as you have but just a straight line by line script. Since you don't pass any parameters into your gosub calls, I don't think they are needed in this script. If you want, things can be passed in and returned and your script setup with some minor changes but in this case I think simpler might be better for you right now as you are learning. Another thing that is possible is you could even have ScriptCards to do spell slot reduction and not shell out to ChatSetAttr but that is optional and totally up to you. This is the output with the above changes. The line only prints one time now:
Thank you Joshua N. so much! :))
Joshua N., or anyone else, The next tasks I assigned myself are to see if the following exist already - or if they might be easy for someone to create - I haven't found them yet: !ScriptCards that resets all the spell slots on a selected character. !ScriptCard that displays the spell slots available for a selected character in the chat window for the selected player only to see. These would let me convert to using Scripts instead of Powercards. Thank you for your assistance!! :)) Barry
So for the 2nd portion first, in the  ScriptCards working examples thread  there are lots of working ScriptCards and the top one in that thread is the Spellbook which will display basically all of that user's spell information to them. And for only the player to see, you can add: --#whisper|self to any ScriptCard that you want only the user to see.  Link to wiki documentation where the whisper parameter is covered As for a ScriptCard to reset spells, I don't know of an existing one that did that since I use a different reset option for long and short rests but here is a quick example for you !scriptcard {{ --/|Reset a selected PC tokens spell slots --/|VARIABLES TO SET --&OutputGMOnly|true --?"[&OutputGMOnly]" -ne "true"|SpellReset --#whisper|gm --:SpellReset| --#title|Spell Reset Example --&CharID|@{selected|character_id} --%lvl|1;9;1 --&total|[*[&CharID]:lvl[&lvl]_slots_total] --?[&total] -eq 0|%! --&remaining|[*[&CharID]:lvl[&lvl]_slots_expended] --+Level [&lvl]|[b]Total: [&total] Remaining: [&remaining][/b] --?[&remaining] -lt [&total]|[ --+|Resetting level [&lvl] slots to [&total] --!a:[&CharID]|lvl[&lvl]_slots_expended:[&total] --]| --%| }} That will loop through the spell slots and reset them to the total. That's an example of the output for resetting a character's 1st and 2nd level slots. Hopefully that's a good enough example for you to modify for your needs. Let me know if anything doesn't make sense. 
Thank you  I'm very happy :))