@fantom Depending how important this is to you / how big a part you want it to play in your game, you could also use extra scripting to allow you to weight / fine-tune the output of *rand accordingly (e.g. based on the protagonist’s skill levels) but wrap it all up in one or more subroutines to limit how much extra coding you will need within your actual story scripting.
For example, if you use percentile (0-100) values for your various main character Stats (we’ll use the example here of a skill called “Command”, for battle tactics) you would begin by defining two new numeric variables in mygame.js, e.g.
,rand_skill: 0
,dieroll: 0
You would then create a subroutine somewhere near the bottom of your scene .txt file, referenced by its own unique label, and also copy this to the bottom of any other scene .txt file in which you wish to make use of it. It might look something like this:
*label rand_sub1
*if rand_skill > 80
*rand dieroll 6 10
*return
*elseif rand_skill > 60
*rand dieroll 5 10
*return
*elseif rand_skill > 40
*rand dieroll 4 10
*return
*elseif rand_skill > 20
*rand dieroll 3 10
*return
*else
*rand dieroll 2 10
*return
This would allow you to weight / fine-tune the actual random number generation according to the current value of the variable “rand_skill”. The random value is stored as the new value of the variable “dieroll”.
Naming this subroutine “rand_sub1” allows you to also use additional subroutines (rand_sub2, rand_sub3, etc.), each weighted differently, so you can for instance have one heavily influenced by current skill level, one only moderately influenced, and one perhaps slightly influenced or only by a very high skill level, etc.
Wherever you wish to make use of this subroutine within your actual story scripting, you would then simply insert the following lines of code:
*set rand_skill command
*gosub rand_sub1
*if (or whatever - using the new value of "dieroll" as required)
With this, we are setting the value of “rand_skill” to equal the current value of the player’s “Command” stat. We could just as easily set it to equal the value of his Leadership skill, his Navigation ability, or his WC-cleaning prowess . . . or whatever other numeric character stat you wish to use in this particular case to influence the returned value of a random “dieroll”.
When ChoiceScipt hits that *gosub line, it will immediately ‘jump’ to the *label referenced there (“randsub1” in this case) and then run that code until it hits a *return command. At that point it will return to the originating *gosub line number (now having determined a new value for “dieroll”, but weighted by the appropriate current skill stat) and will then move on to the *if line immediately below, where you now make use of the new value of “dieroll” within your story scripting as required.
Note that you could also determine which subroutine to use based on something else specific to this particular character, e.g.
*set rand_skill command
*if (born_lucky)
*gosub rand_sub1
*if not (born_lucky)
*gosub rand_sub2
*if (or whatever - using the new value of "dieroll" as required)
Or perhaps use the “born_lucky” boolean as desired within the actual subroutine itself, after it *gosubs there, so you don’t have to add those extra lines each time you want to reference a subroutine in your story scripting.