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 RollQuery In Gosub Issues

Trying to get a ScriptCard working that does some simple branch logic to display a few RollQueries, and then call on an API method to do some logic based on selected options and output a roll template to chat. Final state this ScriptCard will use hideCard and have no output, just a staging point for the roll queries. Basically the players can hire help, and the availability of a given resource-type needs to be rolled. So we have three classes (Henchmen, Mercenaries, Specialists) and a unique list of sub-types beneath each of the three classes. There is also a concept of "Market Class" of the current area, so this information is also gathered. The ScriptCard I have is almost working, but having an issue where my branch-logic based on class is always calling the first RollQuery regardless of the selected value, I think having a RollQuery inside a Gosub might be unsupported? This is my second ScriptCard attempt and never touched PowerCards so new to this bit! Here's what I have now, regardless of what you select for [&HirelingType] you'll always get the Henchmen-specific SubType roll query and not the others. Any insight would be appreciated, where am I going wrong? !scriptcard {{ --#title|Hireling Availability --:Initialize Card| --&HirelingType|?{Hireling Type|Mercenaries|Specialists|Henchmen} --=MarketClass|?{Market Class|VI,6|V,5|IV,4|III,3|II,2|I,1} --?[&HirelingType] -eq Henchmen|>Henchmen; --?[&HirelingType] -eq Specialists|>Specialists; --?[&HirelingType] -eq Mercenaries|>Mercenaries; --+Hireling Type|[&HirelingType] --+Market Class|[$MarketClass] --+Secondary Type|[&SubType] --@hirelingavailability|[&HirelingType] [&SubType] [$MarketClass] --X| --:Henchmen| --&SubType|?{Type|Normal Men,Normal-Men|Level 1,Level-1|Level 2,Level-2|Level 3,Level-3|Level 4,Level-4} --<| --:Specialists| --&SubType|SPECTYPE --<| --:Mercenaries| --&SubType|?{Type|Light Infantry,Light-Infantry|Heavy Infantry,Heavy-Infantry|Bowman,Bowman} --<| }}
1619964919

Edited 1619965702
Kurt J.
Pro
API Scripter
Roll queries are handled by the Chat server before anything gets sent to any API scripts, and the API scripts ONLY see the result of the choices (there is no indication that a roll query happened as far as the script can tell). This means that, for the script above, you will be prompted for HirelingType, MarketClass, and Type as soon as you run the macro, no matter what you choose. You would need to use the --i statement to interrupt the card and request additional information from the player in order to be able to display a roll query mid-script. This would produce a button the player would need to click to cause the prompt to appear. For a little more explanation, when you have this line in your macro: --&HirelingType|?{Hireling Type|Mercenaries|Specialists|Henchmen} The chat server sees it and shows the roll query. What actually gets passed to ScriptCards (or any API script) would be something like: --&HirelingType|Henchmen (Assuming you picked Henchmen). It does this for every roll query in the macro before sending anything to the API scripts. When you have a repeated roll query with the same prompt text (like "Type") the first one will be shown and all subsequent references will just get the value you picked for the first occurrence of the prompt.
Makes sense, thanks. Figured it was something like this since the top-most one was always being evaluated. I went down the path of splitting this into three macros to avoid the branch as --i wasn't working for me... but after seeing your response I figured needed to update from Gist and that did it, so I've got this functioning now, modifications are below. Thanks for the kick in the right direction Kurt! !scriptcard {{ --#hideCard|1 --:Initialize Card| --&HirelingType|?{Hireling Type|Mercenaries|Specialists|Henchmen} --=MarketClass|?{Market Class|VI,6|V,5|IV,4|III,3|II,2|I,1} --C[&HirelingType]|Henchmen:>Henchmen|Specialists:>Specialists|Mercenaries:>Mercenaries --@hirelingavailability|[&HirelingType] [&SubType] [$MarketClass] --X| --:Henchmen| --iHireling Availability Check;Select Henchman Type|q;SubType;Henchman|Normal Men,Normal-Men|Level 1,Level-1|Level 2,Level-2|Level 3,Level-3|Level 4,Level-4 --<| --:Specialists| --&SubType|SPECTYPE --iHireling Availability Check;Select Specialist Type|q;SubType;Specialist|Not|Available|Yet --<| --:Mercenaries| --iHireling Availability Check;Select Mercenary Type|q;SubType;Mercenary|Light Infantry,Light-Infantry|Heavy Infantry,Heavy-Infantry|Slinger,Slinger|Bowman,Bowman|Crossbowman,Crossbowman|Longbowman,Longbowman|Light Cavalry,Light-Cavalry|Mounted Crossbowman,Mounted-Crossbowman|Horse Archers,Horse-Archers|Medium Cavalry,Medium-Cavalry|Heavy Cavalry,Heavy-Cavalry|Cataphract Cavalry,Cataphract-Cavalry|Beast Riders,Beast-Riders --<| }}