How to add random chances for your game?

Been messing with choicescript for couple of days now. got idea that stick and i want to add random chances to my game.

You just need to create a couple temporary variables and use the *rand command to switch between these variables randomly.

A detailed guide of the *rand.

Welcome to the community, Rayred.

As mentioned by Paradox, the *rand command is ideal for random encounters or scenes in a story. You can do a temporary variable, which uses the *temp command, but, personally, I prefer set variables that don’t vanish in new scene documents.

Generally how I approach this, I create what I refer to as a “dice,” which is then “rolled” with the *rand command. As an example:

In Startup Menu
*create dice 0

In A Scene
*rand dice 1 5

*if dice = 1
set dice 0
Text Goes Here or goto_scene

*if dice = 2
*set dice 0
Text Goes Here or goto_scene

*if dice = 3
set dice 0
Text Goes Here or goto_scene

*if dice = 4
set dice 0
Text Goes Here or goto_scene

*if dice = 5
set dice 0
Text Goes Here or goto_scene

Further Commentary About The Above
This is a general approach that I do, which allows for me to continuously create random events or scenes. I generally avoid *temp variables altogether, but I also track dozens of Booleans (True/False Variables) as I go. I have a document that has the code for each Boolean I’ve created, where it came up at, what it means, and if it’s been checked in a later scene or not.

On top of it all, I’m still learning as I go. It works for me, and that’s what matters.

Best of luck with your work!

1 Like

Ok, so theres now an error invalid indent expected atlest one line in ‘if’ true block

You didn’t indent the line properly.

*if ( oranges = "true" ) #I'd like some oranges. 
             You buy some oranges.
             *goto next_scene

*else #I'd like some apples.
     You satisfy yourself with some apples only.
     *goto next_scene

You don’t necessarily have to use a *else and you don’t have to use a *goto after an *if command all the time. Check out the guide I shared earlier, you’ll get some nifty clues regarding *if *else etc in there.

PS - I’m on mobile so the indentation might not be correct. Just add or decrease spaces infront of the line showing the error message.

Thanks, still confused but i think i got it.

Here’s a code snippet to show it in action, where the third choice allows for randomizing the child’s gender. One thing to watch out for: after the randomizer is used, you need to have a *page_break or another choice before the reader can see the results of it. Otherwise, every time they access the stats page and then return to the story, they will end up rerolling, and the text they are currently looking at will change based on that.

*temp gendroll 0
*choice
		#Pink, like her nursery.
				Your little girl coos and shifts, but does not wake.
				*set kidg +1
				*goto nosleep
		#Blue, like the sheets on his crib.
				Your little bundle of joy takes this moment to let out a satisfied burp in his sleep.  Yep, he’s a boy all right.
				*set kidg +2
				*goto nosleep
		#I can't tell, and prefer to let chance decide.
				*achieve randomized
				*rand gendroll 1 2
				*if (gendroll = 2)
						*set kidg 2
						You lean closer and see the tiniest bit of blue cloth poking out from your little guy's bed.
						*goto nosleep
				*else
						*set kidg 1
						You lean closer and see a small strip of pink cloth poking out from your little lady's bed.
						*goto nosleep