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

[Request for Assistance] Nested Roll Queries

Heya, I've managed to create a nested role query.  And it works fine initially when copied into the chat.  Its all split up on multiple lines.  But when I tried to condense it onto one line and use it as part of a character sheet it fails spectacularly and get a, " TypeError: Cannot read property 'substring' of undefined " message. The full nested roll query is as follows: [[?{Difficulty| New Moon, ?{value1| Ragabash,7| Theurge,8| Philodox,8| Galliard,8| Ahrun,8 } | Cresent, ?{value1| Ragabash,8| Theurge,7| Philodox,8| Galliard,8| Ahrun,8 } | Half, ?{value1| Ragabash,8| Theurge,8| Philodox,7| Galliard,8| Ahrun,8 } | Gibbous, ?{value1| Ragabash,8| Theurge,8| Philodox,7| Galliard,8| Ahrun,8 } | Full, ?{value1| Ragabash,8| Theurge,8| Philodox,8| Galliard,8| Ahrun,7 } | Rage Healing, 8 }+?{Rank| Cliath (Rank 1), 0 | Fostern (Rank 2), 0 | Adren (Rank 3), 1 | Athro (Rank 4), 2 | Elder (Rank 5), 2 | Legendary (Rank 6), 2 | }]] Any thoughts as to whats going wrong, how to get this to work.
1635372608
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
The html code for the characters can be eaten by html processors. Since you are coding this directly into the sheet, I'd probably recommend using Roll Parsing for this to mimic a nested roll query. Oosh has some great examples of this sort of thing over in his Adventures with startRoll forum thread.
1635377190

Edited 1635377437
Toby
Pro
I dont really have the time to learn how to code this in javascript regretfully.  Also, from what I can see of the code it would require interaction with the chat window with buttons.  I really wanted to avoid that, I intensely dislike chat buttons.  (I honestly dislike roll queries as well for the exact issue I've run into above, but at least with that you can set up a default value and just keep hitting "enter" to move past the query. The other issue is this needs to occur before the final result ever gets to chat, so.. the example shown is not really something I'd be able to reverse engineer from Adventures with StartRoll(). I will make an attempt at looking at the code but quite honestly I have a game starting up on the 15th, and well.. I need this stuff done for that, I'm already kinda tapped out on what I can do--my own fault I know--but still.. So whatever works, to get it done before that date, I suppose I'll have to do.  Please, advise.
1635379936

Edited 1635380240
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
You can iterate through queries with startRoll. Something like this: <button type='action' name='act_my-button'>nested queries</button> <script type='text/worker'> const queries = { "New Moon":'?{value1|Ragabash,8|Theurge,8|Philodox,8|Galliard,8|Ahrun,8}', "Crescent":'?{value1|Ragabash,8|Theurge,7|Philodox,8|Galliard,8|Ahrun,8}', "Half":'?{value1|Ragabash,8|Theurge,8|Philodox,7|Galliard,8|Ahrun,8}', "Gibbous":'?{value1|Ragabash,8|Theurge,8|Philodox,7|Galliard,8|Ahrun,8}', "Full":'?{value1|Ragabash,8|Theurge,8|Philodox,8|Galliard,8|Ahrun,7}' }; const iterateButtonQueries = async function(event,query = '?{Difficulty|New Moon|Crescent|Half|Gibbous|Full|Rage healing,8}'){//Tag the function as asynchronous so we can await startRoll let response = await extractQueryResult(query); console.table({response}); if(+response){//if the response is a number, finish the iteration //Do the rank query let finalResponse = await extractQueryResult('?{Rank|Cliath (Rank 1), 0 |Fostern (Rank 2), 0 |Adren (Rank 3), 1 |Athro (Rank 4), 2 |Elder (Rank 5), 2 |Legendary (Rank 6), 2 |}') //Send the total formula to chat console.table({finalResponse}); let totalRoll = await startRoll(`&{template:default} {{difficulty=[[${finalResponse} + ${response}]]}}`); finishRoll(totalRoll.rollId);//finish the roll. Your final worker may have computation that would need to be done before finishing the roll. }else{//otherwise keep working through the iteration iterateButtonQueries(event,queries[response]); } }; const extractQueryResult = async function(query){ let queryRoll = await startRoll(`!{{query=[[0[response=${query}]]]}}`); finishRoll(queryRoll.rollId); return queryRoll.results.query.expression.replace(/^.+?response=|\]$/g,''); }; on('clicked:my-button',iterateButtonQueries); </script> Gives a user experience like this (click to play gif): This is a pretty basic example without any bells and whistles like being able to pass the selected pass to later iterations or labeling each value with the option text that was in the query for it. All those are possible, they just require a little more set up.
I will use this to try and learn what needs to be done to shove the roll query into an existing roll if I'm able.  Thank you.  I'd give you a date when I think I'd have things done, but the truth is...  The truth is I really really screwed up on how complicated all of the rules are for the various rolls.  And how they need to be handled.  There is alot more interconnectivity than I originally thought. It is clear why no one has ever tried to create a unified version of the WoD sheets in the past...  Its has a monstrous amount of stuff involved.  As it stands I've written the rules for only about half of the major rolls.  And to add a cherry to my wonderful evening... I just discovered that r20 has been trying to reach out to me for the past two weeks about a declined card..  Cause I wasnt paying attention I just noticed.  I am truly a scatterbrain.