This short update returns multiple potion instead of one at a time.
This is part 6 of a series of articles on Creating a Random Generator. Part 5 is here. And part 7 is here
Multiple Potions
Many times a randomly generated result isn't what we want. But when ten are returned at once, we're more likely to find one we like.
We're updating our potions generator to let the number of potions be chosen. By default we'll return 5 when the generator is used but this can be changed in a dropdown.
Perchance Multiple Potion Results
In perchance we'll need a variable for the number of potions to create. As we want 5 potions we'll set it to this by default.
potion_results = 5
To be able to reuse the potion templates in one place we'll move them to new section "potion_template".
In the main perchance "output" section then becomes the magical line
[potiontemplate.selectMany(potionresults).joinItems("<br /><br />")]
Here the main potion template "potiontemplate" is being repeated a number of times as determined by "potionresults". Each result has two new lines added to it in the form of HTML < BR /> tags.
In the HTML window of perchance the code for the dropdown is added
The option for "5" comes first as the generator is returning 5 results by default. The first value in the list is used as the starting value.
So now the perchance potion gen v.6 returns 5 potions by default using our various templates.
Chartopia Multiple Potion Results
In Chartopia we can create the "Potions" Input Variable with values of 5, 1, 10, 25 and 100. The 5 comes first as we want 5 values by default and for this the first value is used.
Our template is already setup in the main generator so we need to wrap it in a loop.
{% for results in range from: 1 to:{$Potions} %}
Says that we will repeat the enclosed piece of code. Repeated a number of times equal to the value of our Potions dropdown.
{% end %}
The "end" marks the bottom of our template to be wrapped. We want to wrap the "rolled_effect=" part so that we get a different potion effect each time
The main potion template has also been updated with a cosmetic update to the "{%rolled_effect=" line
It now looks like.
And the updated Chartopia potion gen
Finishing Up
So now the potion generators can provide 1 to 100 results as chosen by the potion seeker.
New versions of Chartopia Potions and Perchance Potions are up.
Any questions or requests welcome.
If you've got feedback leave a comment, head on over to r/rpg_generators at reddit or come join the Rand Roll discord server.