Is it possible to include *chances* of failure in options?

Is it possible to have a chance to fail something?

I know about the:
*rand variable_here 5 10
script, but is it possible to do something akin to this:

Your character has to have at least 60 dexterity to pick the option “Jump over the river” but a dexterity of 80 to actually move on from it. They select the option with exactly 60 dexterity, so they are able to attempt. The game rolls a set of numbers to determine if the player wins the roll. Since his dexterity is 60, he fails and the river washes him away to a different chapter setting than the one he would have gotten to if he won.

He tries again after he beats the game, reaching this choice with a dexterity of 60. The game rolls a set of numbers and he gets lucky and wins the roll this time, crossing the river and making it to a new chapter he missed out on before.

A second player comes along with 90 dexterity. Since his dexterity is over 80, he doesn’t have to attempt the roll and goes on.

Is the preceding scenario at all possible to code into a ChoiceScript game? If so, I would love to know it. The closest I’m getting is:
*rand dexterity 60 100
But that will check for a winning number of 80 or higher with the setback of changing the variable permanently. So is there a way to maybe save a variable, randomize it, check the number, and return to the saved variable?

Or maybe something else entirely.

Bottom-line: Is the scenario possible to code?

I think this is what you want:

How do you want to cross the river? *choice *if dexterity >= 80 #Jump the River *goto JumpRiver *if (dexterity >=60) and (dexterity <80) #Jump the River *rand chance 1 4 *if chance > 2 *goto JumpRiver *else *goto WashedAway

In the above, a player only sees one choice for Jump the River. If dexterity is 80 or over, they are taken automatically to the section JumpRiver. If dex is between 60 and 80, the game rolls and gives a 50% chance to Jump the River.

Yeah, you can do that with Choicescript. You just have to make another variable to hold the random number. Then you can do something like this:
*rand random_variable_thing 0 20 *set dexterity_plus_random_variable (dexterity + random_variable_thing) *if dexterity_plus_random_variable > 79 Awesome, you didn't die! *goto survived *else It is a shame that your adventures have ended here. *goto death
There I kept the dexterity variable intact, and made a separate variable that is bigger or smaller depending on dexterity. This variable was also bigger or smaller depending on a random number. If that new variable was big enough (80 or higher), then the player would get the good result. Also notice that the player is guaranteed success if their dexterity is 80. The higher their dexterity is, the higher the chance is that they will get a big enough dexterity_plus_random_variable. At dexterity of 60, the chance is one in 20 (1/20) that the player will get the good result. This is far from the only way you can do this - you don’t have to make dexterity_plus_random_variable… dexterity plus the random variable. You can change how dexterity and the random variable are weighted against each other (which one is more important in deciding the result) by making one of them count twice as much for dexterity_plus_random_variable (dexterity + (2 * random_variable_thing)). Just make sure that you change other numbers (like the 79 in the if statement) so that it doesn’t give you autosuccess or autofailure when you don’t want it.

You can also make 80 an autosuccess, and then make 60 through 79 random, like so:

*if dexterity > 79 You easily manage to get passed the traps. *goto survived *else *rand random_variable_thing 0 1 *if random_variable_thing = 0 You barely managed to get passed the traps. *goto survived *else Your head was smashed in by the first trap you ran into. *goto survived

Again you can change values around. You can also make dexterity factor into the 60 to 79 dexterity if statement so that higher dexterity increases the chance of success.

I chose to use giant names for my variables to help show what they were. Generally you would not make them have giant_variable_names_of_doom like that. Also, you can be semi-fancy and skip making what would be your equivalent to my dexterity_plus_random_variable variable, and use “(dexterity + random_variable_thing)” instead, like so:

*if (dexterity + random_variable_thing) > 79

I hope this helped. Good luck with Choicescript, and I look forward to seeing your game(s).

Edit: @JimD You ninja’d me :(. Also want the dexterity-testing if statements nested inside of “#Jump the River” or that second dexterity-testing if statement to be an elseif. If not players with 80+ dexterity will see two options.

Sorry for the ninja-ing. One note, with my method, a player won’t see both choices in the way I wrote it. If your dex is 81, you won’t even see the second choice. I do this a lot in my game.

Oops you’re right JimD. I didn’t look close enough at your code.

One question, @peglegpenguin

In your first suggestion (which look like what I want, your chances of success up to auto-success are higher depending on how much higher your stat is), there is something I wanted to know.

*set dexterity_plus_random_variable (dexterity + random_variable_thing)

Let’s say I have dexterity of 60 and the random variable was 20. This would change my dexterity to 80, making me pass. But I didn’t see any code after the *goto survived code that would set my dexterity back to 60.

So would I succeed the roll with a dexterity of 80 and continue with my dexterity being 80? Or is the fact that “dexterity + random_variable_thing” was in parenthesis

dexterity_plus_random_variable would be a new variable adding your dexterity (60) to the random variable. The original dexterity variable would remain at 60.

Oh, I see. I just ran a test of this as it’s own game. Worked like a charm. Thanks everyone! :slight_smile:

You might also want to take a look at a topic further down the page called ‘Randomness’. I faced a similar dilemma a while back and there were some very helpful posts made in there, too, including a very good analysis on when to use (and when not to use) random elements in a ChoiceScript game.

what do I click on in the mess of files to autotest or quicktest?

For Windows it’s the .bat file of that name found in the dfabulich-choicescript-(id number) folder.

Being batch files, you need to run them in the command window.

It could definitely do with a help / guidelines page on this subject. It took me at least half an hour to figure it out, and then only because I’m actually ancient enough to remember MS-DOS, before Windows even existed (the command window uses the old DOS commands, such as “cd” to Change Directory).

Ugh ok. Thanks.I’ve played with command prompt a little. It seems like a pain in the butt. I’ve been letting my little brother play it till he runs into an error I can fix.