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

Scriptcard GOSUB Problem

I am trying to recreate this table: The code is currently as follows: !script {{   --#title|Point of Interest   --=POI|[T#PointofInterest]   --+|[$POI.tableEntryText]   --?[$POI.tableEntryText] -inc "Deep-space station" | [ >DSS   --]|[ --?[$POI.tableEntryText] -inc "Asteroid base" | [ >AB   --]|[ --?[$POI.tableEntryText] -inc "Remote moon base" | [ >RMB   --]|[ --?[$POI.tableEntryText] -inc "Ancient orbital ruin" | [ >AOR   --]|[ --?[$POI.tableEntryText] -inc "Research base" | [ >RB   --]|[ --?[$POI.tableEntryText] -inc "Asteroid belt" | [ >ABelt   --]|[ --?[$POI.tableEntryText] -inc "Gas giant mine" | [ >GGM   --]|[ --?[$POI.tableEntryText] -inc "Refueling station" | [ >RS   --]|[       --+|"Doesn't work" --]|   --X|   --:DSS|    --=OC|[T#POIOccupantDSS]       --*Occupied By|[$OC.tableEntryText]   --=OS|[T#POISituationDSS]       --*with the situation|[$OS.tableEntryText]   --<|   --:ABase|       --=OC|[T#POIOccupantABase]   --*Occupied By|[$OC.tableEntryText]   --=OS|[T#POISituationABase]   --*with the situation|[$OS.tableEntryText]     --<|   --:RMB|       --=OC|[T#POIOccupantRMB]   --*Occupied By|[$OC.tableEntryText]   --=OS|[T#POISituationRMB]   --*with the situation|[$OS.tableEntryText]   --<|   --:AOR|       --=OC|[T#POIOccupantAOR]   --*Occupied By|[$OC.tableEntryText]   --=OS|[T#POISituationAOR]   --*with the situation|[$OS.tableEntryText]   --<|   --:RB|       --=OC|[T#POIOccupantRB]   --*Occupied By|[$OC.tableEntryText]   --=OS|[T#POISituationRB]   --*with the situation|[$OS.tableEntryText]   --<|   --:ABelt|       --=OC|[T#POIOccupantABelt]   --*Occupied By|[$OC.tableEntryText]   --=OS|[T#POISituationABelt]   --*with the situation|[$OS.tableEntryText]   --<|   --:GGM|       --=OC|[T#POIOccupantGGM]   --*Occupied By|[$OC.tableEntryText]   --=OS|[T#POISituationGGM]   --*with the situation|[$OS.tableEntryText]   --<|   --:RS|       --=OC|[T#POIOccupantRS]   --*Occupied By|[$OC.tableEntryText]   --=OS|[T#POISituationRS]   --*with the situation|[$OS.tableEntryText]   --<| }} The only output is the Point of Contact and "doesn't work" meaning that all of the conditions are skipped. Any suggestions?
1647465245
Andrew R.
Pro
Sheet Author
Try removing the space between’|’ and ‘[‘ on your —? lines. 
Didn't work.
1647516932

Edited 1647518947
David M.
Pro
API Scripter
I would add some temporary print statements in your conditional code blocks and also at the start of each subprocedure to help nail down where the problem is. Or add a --#debug|1 statement at the top and look through the api console after running your scriptcard to see what the parser is seeing. You could also simplify your conditionals syntax since they are only calling the appropriate subprocedures. So rather than using code blocks your conditionals could be written like this. Technically this might run a few more cpu cycles but shouldn't be noticeable. --?[$POI.tableEntryText] -inc "Deep-space station"|>DSS --?[$POI.tableEntryText] -inc "Asteroid base"|>AB --?[$POI.tableEntryText] -inc "Remote moon base"|>RMB --?[$POI.tableEntryText] -inc "Ancient orbital ruin"|>AOR --?[$POI.tableEntryText] -inc "Research base"|>RB --?[$POI.tableEntryText] -inc "Asteroid belt"|>ABelt --?[$POI.tableEntryText] -inc "Gas giant mine"|>GGM --?[$POI.tableEntryText] -inc "Refueling station"|>RS Another possibility could be strange whitespace characters hidden in there depending on what editor you are using to write this.
1647518822
GiGs
Pro
Sheet Author
API Scripter
Also, since it looks like you are essentially rolling on one table, then two more based on that first table, you could try the Aaron's Rollable Tables script - I don't remember the script name, but it is designed for this purpose and might be easier.
1647526240

Edited 1647575385
timmaugh
Pro
API Scripter
Or a Mule (Muler script, with ZeroFrame, too). The results of that retrieval operation could then be passed to a simple ScriptCard... or to a roll template. One Mule could be for the Point of Interest: 10=Deep-space station 20=Asteroid base 30=Remote moon base 40=Ancient orbital ruin 50=Research base 60=Asteroid belt 70=Gas giant mine 80=Refueling station (I am multiplying the d8 by 10 to make the next steps easier) Another Mule could be for the Occupied by: 11-12=Dangerously odd transhumans 13-14=Freeze-dried ancient corpses 15-16=Secretive military observers 17-18=Eccentric oligarch and minions 19-20=Deranged but brilliant scientist 21-22=Zealous religious sectarians 23-24=Failed rebels from another world 25-26=Wage-slave corporate miners 27-28=Independent asteroid prospectors 29-30=Pirates masquerading as otherwise 31-32=Unlucky corporate researchers 33-34=... 35-36=... That list would go on to 90. Notice how at 21 it flips over to the 20 result from the first table. That's because we retrieve a value from the first Mule with a [[1d8*10]] used in a get statement: get.MuleCharacter.PointOfInterest.[[1d8*10]].value/get ...and we retrieve a value from the second Mule with that first die roll plus a 1d10 (range 1 to 10): get.MuleCharacter.OccupiedBy.[\][\]$[[0]] + [[1d10]].value\]\].value/get Obviously, I'm naming the Mules (abilities on a character, somewhere) "PointOfInterest" and "OccupiedBy", and they are stored on a character named "MuleCharacter." You'd have one more Mule for the "Situation" table, with a similar call. Finally, you'd need to load your Mules in the same message command line, so you'd need a {&mule} statement: {&mule MuleCharacter.PointOfInterest MuleCharacter.OccupiedBy MuleCharacter.Situation} All of these retrieval operations would happen before ScriptCards got a hold of the command line, so your ScriptCard syntax could simplify down to just using the variables returned from the Mule get statements. Not only does this make your ScriptCard code even more flexible, it allows you to use the same tables in other places at other times. If they are hard-coded into a ScriptCard procedure, you have to copy/paste them into a new ScriptCard macro if you want to use them again (or build a library -- you can build a library in SC, right?). Point is, with a Mule, you can use the same bank of information in a ScriptCards macro, in a simple "roll against this table" mechanic, or in a roll template. Here is the same set of Mules applied to a roll template output: !&{template:default}{{name=Point of Interest}}{{A point=get.MuleCharacter.PointOfInterest.[[1d8*10]].value/get}}{{Occupied By=get.MuleCharacter.OccupiedBy.[\][\]$[[0]] + [[1d10]].value\]\].value/get}}{{Situation=get.MuleCharacter.Situation.[\][\]$[[0]] + [[1d10]].value\]\].value/get}} {&simple} {&mule MuleCharacter.PointOfInterest MuleCharacter.OccupiedBy MuleCharacter.Situation}
I like the mule script idea, but I've never done one. How does that work? I created the mule tables: PointOfInterest, POIOccupiedBy, and POISituation with the values as you described above. I don't understand what to do to make use of them.
1647538632

Edited 1647575327
timmaugh
Pro
API Scripter
I'll list all of the steps here... you might have already accomplished some of these. Just read through to make sure, and post back with any questions. 1. Install Scripts The first step is to have Muler and ZeroFrame installed (both available in the one-click). 2. Create Mule Character Create a character (or choose one) to house the Mules (abilities). Make sure that anyone who would need to utilize the Mules has access to the character (in other words, if someone is going to need to be able to retrieve a value from a Mule housed on this character, that player will need to be designated in the "Can be controlled by" list). For my examples, I'll pretend you have named this character "MuleCharacter". 3. Create the Mules Again, the Mules are abilities on the character, so create 3 abilities. You just indicated you want them named PointOfInterest, POIOccupiedBy, and POISituation. Construct them as: VariableName=VariableValue Spaces matter around that equals sign... so if there's a space on the left, you'll be required to provide that space when you ask for the value. Spaces on the right will be included in the returned value for a given variable. Numeric variables can express less than, less than or equal, greater than, greater than or equal, or a range (ie, 1-2). You're making use of the last one in your POIOccupiedBy and POISituation Mules. 4. Include Your Mule To make the variables of a Mule available within a macro (that is, available to be used in your command line), you have to use the {&mule} syntax to get them included. This statement can appear anywhere in your command line *after* the initial exclamation point, and not creating a new line in your command line (ie, don't hit ENTER and then include the {&mule} statement; that will send a new message through). Basic structure is: {&mule CharacterA.Mule1 CharacterA.Mule2 CharacterB.MuleSuchAndSuch CharacterC.MuleA} For you, you want all three of your Mules available, so for your command, you'll want the following statement somewhere in your command line: {&mule MuleCharacter.PointOfInterest MuleCharacter.POIOccupiedBy MuleCharacter.POISituation} If you want to use the retrieve values in a ScriptCard command, that can go anywhere in your command after the initial ! and as long as it stays on the same last line of the final double closing brackets. SIMPLE EXAMPLE: !{&mule MuleCharacter.PointOfInterest}The value of the [[1d8 * 10]] entry in my Point Of Interest mule is get.MuleCharacter.PointOfInterest.$[[0]].value/get.{&simple} That option just loads one Mule, because that was all I was requesting a value from. 5. Retrieve Values  Anywhere you want to use a value from one of your Mules, use a get statement. Here is the one from the example just above: get.MuleCharacter.PointOfInterest.$[[0]].value/get Rewriting it on different lines might help see what each part is: MULER GET STATEMENT : get. . . /get MULE CHARACTER NAME : MuleCharacter. . MULE ABILITY NAME : .PointOfInterest. VARIABLE TO RETRIEVE: . .$[[0]].value That last value is using a die roll, so we use a ZeroFrame construction ( .value ) to extract the value to make it usable. To take a line from your ScriptCards example, above, if you wanted to assign that to your POI variable (if I understand the SC syntax), that would look like this:   --=POI|get.MuleCharacter.PointOfInterest.$[[0]].value/get By the time ScriptCards gets a hold of the message, the Muler and ZeroFrame scripts have already finished, and what ScriptCards sees is:   --=POI|Remote Moon Base (which brings up a good point: pay attention to when what you return from a Mule might need to be put inside quotation marks -- for instance if it includes a space) Since you'll get the other results (from the other 2 Mules) from the same initial roll and using the associated get statements, you won't need a GOSUB branch to the ScriptCard. You'll just need to either 1) use the get statement returns where you need them, or 2) assign them to a ScriptCards variable (like I just showed) in order to use that variable elsewhere in your ScriptCard macro. For obvious reasons, if you are going to need the value in multiple places, you might as well retrieve it once with a single get statement, assign it to a SC variable, and then let SC use that variable elsewhere in its own code. A NOTE ON {&simple} RETURNS In the "Simple Example", just above, and in the roll template example from my previous message, I use the {&simple} construction. That is a syntax structure that instructs ZeroFrame to not expect another script (like ScriptCards) to be there to pick up the message. Instead, what I want is to output whatever the finished state of my command line is to the chat. That's pretty clear in the "Simple Example" as I'm just trying to output a sentence. "The value of my variable is ...this..." In the roll template example from my previous post, you can see how the various get statements retrieve the values I want for the various roll template parts, and then I use {&simple} again because I want to output the roll template... I don't want the message to continue on to a script. Does all of that make sense?
OK. This is what I put together. !script {{ {&mule MuleCharacter.PointOfInterest, MuleCharacter.POIOccupiedBy, MuleCharacter.POISituation} --#title|Point of Interest --=POI|get.MuleCharacter.PointOfInterest.$[[0]].value/get.{&simple} --+|[$POI.tableEntryText] --=Occupied By|get.MuleCharacter.POIOccupiedBy.[\][\]$[[0]] + [[1d10]].value\]\].value/get.{&simple} --+|[$Occupied By.tableEntryText] --=Situation|get.MuleCharacter.POISituation.[\][\]$[[0]] + [[1d10]].value\]\].value/get.{&simple} --+|[$Situation.tableEntryText] }} But the output comes out like this script {{ --#title|Point of Interest --=POI|get.MuleCharacter.PointOfInterest.1/get. --+|[$POI.tableEntryText] --=Occupied By|get.MuleCharacter.POIOccupiedBy.2/get. --+|[$Occupied By.tableEntryText] --=Situation|get.MuleCharacter.POISituation.5/get. --+|[$Situation.tableEntryText] }} If I use the template version !&{template:default}{{name=Point of Interest}} {{A point=get.MuleCharacter.PointOfInterest.[[1d8*10]].value/get}} {{Occupied By=get.MuleCharacter.POIOccupiedBy.[\][\]$[[0]] + [[1d10]].value\]\].value/get}} {{Situation=get.MuleCharacter.POISituation.[\][\]$[[0]] + [[1d10]].value\]\].value/get}} {&simple} {&mule MuleCharacter.PointOfInterest, MuleCharacter.POIOccupiedBy, MuleCharacter.POISituation} The output is Point of Interest A point get.MuleCharacter.PointOfInterest.50/get Occupied By get.MuleCharacter.POIOccupiedBy.53/get Situation get.MuleCharacter.POISituation.53/get
1647570490
David M.
Pro
API Scripter
Not sure about your muler issue, but I think the problem with your original scriptcard is that you need quotes around both of your conditional terms since they both contain spaces. The following seems like it works for me, though I only populated three tables (PointofInterest, POIOccupantDSS, and POISituationDSS) with one entry each for quick testing.  --?"[$POI.tableEntryText]" -inc "Deep-space station"|>DSS --?"[$POI.tableEntryText]" -inc "Asteroid base"|>AB --?"[$POI.tableEntryText]" -inc "Remote moon base"|>RMB --?"[$POI.tableEntryText]" -inc "Ancient orbital ruin"|>AOR --?"[$POI.tableEntryText]" -inc "Research base"|>RB --?"[$POI.tableEntryText]" -inc "Asteroid belt"|>ABelt --?"[$POI.tableEntryText]" -inc "Gas giant mine"|>GGM --?"[$POI.tableEntryText]" -inc "Refueling station"|>RS
1647575173
timmaugh
Pro
API Scripter
Two things... First, I made a mistake with my {&mule} statement. It shouldn't be comma separated. Just separate them with a space: {&mule MuleCharacter.PointOfInterest MuleCharacter.POIOccupiedBy MuleCharacter.POISituation} I altered the template statement (above), and it worked for me. I'll go back and correct my first post to remove the commas. Second, for your ScriptCards example, you don't want the {&simple}. You WANT the command/message to continue on to the recipient script (in this case, ScriptCards). The {&simple} tag tells ZeroFrame that when all of the meta-script operations are done, we want this to *stop* being an API message and turn into a standard message (where what is left of the command line is output to the chat interface). That works for something like a roll template output, but when you want ScriptCards to take over when the meta stuff finishes, you don't want the {&simple} tag.
David M. said: Not sure about your muler issue, but I think the problem with your original scriptcard is that you need quotes around both of your conditional terms since they both contain spaces. The following seems like it works for me, though I only populated three tables (PointofInterest, POIOccupantDSS, and POISituationDSS) with one entry each for quick testing.  --?"[$POI.tableEntryText]" -inc "Deep-space station"|>DSS --?"[$POI.tableEntryText]" -inc "Asteroid base"|>AB --?"[$POI.tableEntryText]" -inc "Remote moon base"|>RMB --?"[$POI.tableEntryText]" -inc "Ancient orbital ruin"|>AOR --?"[$POI.tableEntryText]" -inc "Research base"|>RB --?"[$POI.tableEntryText]" -inc "Asteroid belt"|>ABelt --?"[$POI.tableEntryText]" -inc "Gas giant mine"|>GGM --?"[$POI.tableEntryText]" -inc "Refueling station"|>RS That fixed the problem with the original script. Thanks.