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 -- Randomizing text output to chat box.

Thanx Muchly in advance for any help!! I'm loving Kurt Jaeger's ScriptCards,... even though I'm terribly ignorant to the flow of programming. I'm trying to adapt a couple of scripts I found to fit the needs of my situation, and wondering if there is a way to "randomize" the text in the output to the chat window.  VERY basic scripts so far,.. just the Long Sword Attack script for now.   What i'm hoping for is, for example, every time a "fumble" result occurs it says  " The attack went horribly wrong." The line that produces this text is simply: --+Fumble!|The attack went horribly wrong. Is there a way to put in a randomized function to add different variations to this text...  so that maybe sometimes it says... "Oops! that didn't work out."  or  "Look out everyone!" instead of just the same result every time? This would be useful in any place within the script that a text result accompanies other variables...   Also...  it would be useful to be able to possibly alter what the "text statement" is based on the result of a die roll?   As in.. if a character rolls a "Crit" and maxxed out the die rolls, the text could say...  "Wow [29]  slashing damage really ruined that Orc's day!"   vs. if the character rolls a "Crit" and all the dice roll 1's...  and the text could say...  "Um, sure seemes like it should have been more than [8].  Maybe You should sharpen your sword." I hope this makes sense, and it's prolly an easy {but likely tedious and repeditive} fix... but would be another little bit of fun for the players to see different statements in the text.
Hey Dink, One possible way to do this is to setup a series of rollable tables with phrases you'd like to have. You could then have ScriptCards conditionally roll on the appropriate roll table to output the phrase. You can even add ScriptCard references and variables in the phrases. So if you have a Roll variable named $TotalDamage you can use that in the roll table text and ScriptCards will replace it when outputting the text.
Hey there Joshua! Thanx for the response!  Honestly didn't expect one so quickly! What You suggest sounds like what I'm kinda looking for!  I've used the rollable tables before, more for creating multi-sided tokens, but could figure that part out... What I don't know how to do is to get ScriptCards to roll on the table,... nor how to get it to use that in the text block...
1718415226

Edited 1718415257
Andrew R.
Pro
Sheet Author
For example,  !script {{ —/| Roll on the FruitTable rollable table  —=Fruit|[T#FruitTable]  —/| Extract the text  —&TextOfFruit|[$Fruit.tableEntryText]  …  }}
Hello Andrew! Thank You Muchly Good Sir!  will give it a shot! btw... is there a page that is more "ignorant old man" friendly that shows all of the available...  well,.. thing and symbols at the beginning of each line and what they do?  I know the wiki has it all,. but I'm just about to retirement age, and besides bad eyes,..  that's a lot of filtering.... lol.   I understand many of them as I "Dink" around with em...
well,.. not sure where the disconnect is,.. cept for the missing brain cells... but I have tried a couple dozen ways to fit it into this and it either just types out what is in the script.. or types out nothing...  this is the script for the function...  but I can't figure out how to fit it in...   --:Fumble|   --+Fumble!|The attack went horribly wrong.   --^Final| I called the roll table AttackFumble because I didn't want it to be mistaken in the script for the "Fumble", and added 4 entries all weighted at 25. not seein what to replace "fruit" with and where to put what You suggested into the already written script.
Here is a quick example with 3 different tables, MissPhrases, HitPhrases, and CritPhrases. !script {{ --&MissTableName|MissPhrases --&HitTableName|HitPhrases --&CritTableName|CritPhrases --#sourceToken|@{selected|token_id} --#targetToken|@{target|token_id} --=AtkRoll|1d20 + [*S:pb] + [*S:strength_mod] --?[$AtkRoll.Base] -eq 20|Crit --?[$AtkRoll] -ge [*T:npc_ac]|Hit|Miss --:Done| --X| --:Miss| --=MissPhrase|[T#[&MissTableName]] --+MISS|[$MissPhrase.tableEntryText] --^Done| --:Hit| --=HitPhrase|[T#[&HitTableName]] --=TotalDamage|1d8 + [*S:strength_mod] --+HIT|[$HitPhrase.tableEntryText] --+Damage|[$TotalDamage] --^Done| --:Crit| --=CritPhrase|[T#[&CritTableName]] --=RegularDamage|1d8 + [*S:strength_mod] --=CritDamage|1d8 --=TotalDamage|[$RegularDamage] + [$CritDamage] --+CRIT|[$CritPhrase.tableEntryText] --+Damage|[$TotalDamage] --^Done| }} So you can see that in this example table I've put in [$TotalDamage] and [*T:npc_name] which will get substituted by ScriptCards in the output above since there is a `--=TotalDamage` roll variable and using the --#targetToken attribute referencing. --=MissPhrase|[T#[&MissTableName]] --+MISS|[$MissPhrase.tableEntryText] You can see in the above snippet from the --:Miss| label that it will  roll on the table  and output the entry rolled as direct output . The --:Hit and --:Crit labels are similar but with damage rolls. Hopefully that example can help you with your ScriptCard.
1718434504
Andrew R.
Pro
Sheet Author
OK, a very simple example. It's best to start simple with ScriptCards and work up to complex things.  !script {{ --/| Roll on the AttackFumble rollable table --=FumbleRoll|[T#AttackFumble] --/| Extract the text from the FumbleRoll --&FumbleText|[$FumbleRoll.tableEntryText] --/| Print the FumbleText --+Fumble|[&FumbleText] }} Dink said: well,.. not sure where the disconnect is,.. cept for the missing brain cells... but I have tried a couple dozen ways to fit it into this and it either just types out what is in the script.. or types out nothing...  this is the script for the function...  but I can't figure out how to fit it in...   --:Fumble|   --+Fumble!|The attack went horribly wrong.   --^Final| I called the roll table AttackFumble because I didn't want it to be mistaken in the script for the "Fumble", and added 4 entries all weighted at 25. not seein what to replace "fruit" with and where to put what You suggested into the already written script.
1718456563

Edited 1718456740
Dink
Pro
Thank You Muchly Good Sirs! Extremely good information all around and I'm hopeful that this will be workable.  As much as I often enjoy the convenience of cutting and pasting the work of others, it's not always possible to find a script that fits the specifics of a situation.  Learning how these scripts work helps to personalize them to the players involved.  Thanx again Very much for Your efforts.   btw.. I assume the lines that start with --/| "blah blah"  are just informative and explaining what the next line is doing...  
1718459571

Edited 1718459588
Yep. `--/|` is a  ScriptCards comment . It doesn't get executed so it is what you use to document the code in ScriptCard for reference.
ok.. back again,...  have gotten several things to work very well thanx to You'z'n's help.  Thanx again Muchly!  Fumbles and Crits,..with tables and multiple texts are working great! Now running into another issue.    I've created a section? of the script that deals with the miss function.  The idea is actually to access 2 rollable tables.  The first is called "Comment" and is a list of the names of the characters in the party.  The second table is called "AttackMiss" and it is a snide comment that they say when the player misses.  The section? (i don't know what to call these little parts of the script) anyway,.. The section works great for the most part!  When they miss,.. it chooses a name, and a comment and displays it into the chat just fine!  However,.. sometimes it chooses the player that missed the attack,...so they're chiding themselves.  I'm trying to use a loop so that if the outcome of the Comment table is the selected players name,.. it will run the Comment table again until it gets a different result.  But am still getting the same person as shown below.   please excuse that I don't know how You'z'n's get that neat box around Your script samples. Here is the section? of the script (btw... I tried the "loop|while" with -inc also.. neither worked): --=AttackerName|@{selected|token_name}   --=CommentRoll|[T#Comment] --&CommentText|[$CommentRoll.tableEntryText] --/| The problem loop? --%loop|until;[$CommentText] -ninc [$AttackerName] --=MissRoll|[T#AttackMiss] --&MissText|[$MissRoll.tableEntryText] --+Miss!|[&CommentText] [&MissText] --^Final|
So there are a couple things that I changed. You had an until loop but never closed the loop. All loops need to be closed with a `--%|`. You also never reroll in your loop so if you hit a problem you never reroll on the table to get a new value. --&AttackerName|@{selected|token_name} --:ROLLCOMMENTER| --=CommentRoll|[T#Comment] --?"[&AttackerName]" -eq "[$CommentRoll.tableEntryText]"|ROLLCOMMENTER --=MissRoll|[T#AttackMiss] --+Miss!|[$CommentRoll.tableEntryText] [$MissRoll.tableEntryText] So this is one way to do it, you use a  Branch Label  --:ROLLCOMMENTER| and then use a conditional statement --?  to check if the text from the table is equal to the selected token name and if it is, then we jump back to the ROLLCOMMENTER branch and go from there. This could loop over and over again if we get unlucky or there was only 1 entry in the table. Once the CommentRoll text doesn't equal the &AttackerName string variable, then it will proceed past the conditional and roll on the AttackMiss table and output the line. There are other options you can use to accomplish the same but this should work without looping over anything. As an aside the code blocks are available in the reply in the Style dropdown:
Hello Again!    Excellent!!  Thanx again MUCHLY!!   Having "if" "then" "goto" "return" flashbacks of sitting at the TRS-80 in my accounting class,.. circa.. 1982.  LoL. I also noticed that You took out the   " --&MissText|[$MissRoll.tableEntryText] and " --&CommentText|[$CommentRoll.tableEntryText]"  lines and only used what i circled in the image.    Is this to save space,.. because they were only going to be used the one time and there was no need to assign a name to the function?
Yeah. I used the Roll variable output directly without setting a String variable with the output because didn't need to manipulate the string in any way. You can add it back in, if you prefer. Either way should output the same thing just with slightly more variable substitutions set and performed. 
NoSir,..   no need to change it,. just wanted to make sure I understood what I was seeing.  Thanx Again!!
1718565176

Edited 1718565511
Dink
Pro
Is there a good resource for sample scripts that folx'z are sharing?  I've found a few, but somehow I believe that with as powerful as this is,.. there is a Huge number of scripts out there that I'm missing.  I am enjoying adopting the few I've found to my group's needs, and even those that I've found that I'm not interested in,. I'm enjoying reading through them and figuring out the logic in them,.. and how that could influence others that I might actually use. I'm interested in learning how to use symbols in the text outputs.. skulls or flames.. or even gifs {like i found in someones Poison Spray script).  I'm also going to have to figure out how to easily calculate the hex codes for colors.  Also,.. as well as learning how the scripts apply damage to targets, or healing if that be the case,.. I'm hoping to learn how to have the scripts access other API's like tokenMod for example, to add condition markers, and their effects... like blind turning off the tokens vision for the appropriate durations?   Lastly,.. while adjusting the scripts I'm working on,.. when applying attack bonuses,. or AC's to the calculations to determine hits,.. I've found I have to manually apply the specifics for the weapon according to the character.  Is there a way to have the script access the damage type, magic bonus etc. unique to a weapon?  Even if there has to be a separate button for each weapon,.. this would make the script more flexible when applying it to different characters without having to manually add the numbers... Thanx for all the help so far.  It has been invaluable in my journey down this rabbit hole,.. "re-learning" logic in the function of the scripts. btw --  If the thought "doesn't this guy have anything else to do??"  the answer is in all honesty,.. not really,..  LoL.. I'm retired and don't have access to my Golf clubs, so I spend most of my time flying in World of WarPlanes,..or DCS... and prepping my D&D Campaign for my group, which actually includes a couple of my adult children.
So the ScriptCards wiki  includes links to a few places where you can find scripts like  Roll20 sharing thread ,  Kurt J's github , and the user submitted scripts wiki . Lots of places have hex code color options, here is one a quick Google search . There is also a few tutorials  here  with the intent on walking people through various ScriptCards functions. So like Tutorial 1 has a section where it shows how to apply damage to a target directly with scriptcards. Tutorial 2 gives some examples of working with repeating sections on character sheets since many sheets, including the common D&D5e sheet by Roll20, put Attacks and Weapons in repeating sections. So Tutorial 2 shows how you can grab the information from repeating sections and use them in ScriptCards. There is not a tutorial currently that shows how to call other mods, `--@` syntax, but that should hopefully be done soon. Kurt J also has a  ScriptCard library  with a function you can use to apply damage or healing to a token. That same library also has functions for modifying status markers . So you can modify most objects directly with ScriptCards. The ScriptCards wiki also includes a link to the ScriptCards Discord server which has a lot of knowledgable and helpful folks that can answer questions and share their ScriptCards as well.
Thanx again Muchly!  Great info!
ok... lol.. another question.....   Several scripts.. like Fireball...  display in the text and display the names of the targets involved.   Until the characters know what the "targets" (type, name, etc. of a creature) i'd rather it not name them by actual name.  However,.. I can't just change the line that display's the name, because then I wouldn't even be able to tell which is which to apply the damage.   Note here:  I'm working through the scripts and disabling the automatic damage application because not everyone uses the same "bars" and half the time I end up taking points away from AC or... I use the extra for "passive_wisdom" so I don't always have to ask.  NEWAY...  I know that output can be whispered, but is there a way to take out the names of the targets, without removing them completely, but whisper the names to the DM/GM?  I need them, but the players don't.