# How to add random chances for your game?

**URL:** <https://forum.choiceofgames.com/t/how-to-add-random-chances-for-your-game/114263>\
**Category:** ChoiceScript Help\
**Created:** [February 17, 2022, 3:37am UTC](https://forum.choiceofgames.com/t/how-to-add-random-chances-for-your-game/114263 "2022-02-17T03:37:43Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rayred](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/rayred/32/163325_2.png) [@Rayred](https://forum.choiceofgames.com/u/Rayred)\
**Post date:** [February 17, 2022, 3:37am UTC](https://forum.choiceofgames.com/t/how-to-add-random-chances-for-your-game/114263/1 "2022-02-17T03:37:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Paradox1](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/paradox1/32/144382_2.png) [@Paradox1](https://forum.choiceofgames.com/u/Paradox1)\
**Post date:** [February 17, 2022, 4:10am UTC](https://forum.choiceofgames.com/t/how-to-add-random-chances-for-your-game/114263/2 "2022-02-17T04:10:19Z")

</div>

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.](https://retowers.neocities.org/CSGuide/CSGuide.html)

---

<div class="post-metadata">

**Author:** ![TheChaosArchivist](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/thechaosarchivist/32/162222_2.png) [@TheChaosArchivist](https://forum.choiceofgames.com/u/TheChaosArchivist)\
**Post date:** [February 17, 2022, 4:43am UTC](https://forum.choiceofgames.com/t/how-to-add-random-chances-for-your-game/114263/3 "2022-02-17T04:43:54Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Rayred](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/rayred/32/163325_2.png) [@Rayred](https://forum.choiceofgames.com/u/Rayred)\
**Post date:** [February 17, 2022, 7:01am UTC](https://forum.choiceofgames.com/t/how-to-add-random-chances-for-your-game/114263/4 "2022-02-17T07:01:02Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Paradox1](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/paradox1/32/144382_2.png) [@Paradox1](https://forum.choiceofgames.com/u/Paradox1)\
**Post date:** [February 17, 2022, 8:46am UTC](https://forum.choiceofgames.com/t/how-to-add-random-chances-for-your-game/114263/5 "2022-02-17T08:46:54Z")

</div>

You didn’t indent the line properly.

```nohighlight
*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.

---

<div class="post-metadata">

**Author:** ![Rayred](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/rayred/32/163325_2.png) [@Rayred](https://forum.choiceofgames.com/u/Rayred)\
**Post date:** [February 17, 2022, 9:46am UTC](https://forum.choiceofgames.com/t/how-to-add-random-chances-for-your-game/114263/6 "2022-02-17T09:46:48Z")

</div>

Thanks, still confused but i think i got it.

---

<div class="post-metadata">

**Author:** ![hustlertwo](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/hustlertwo/32/34230_2.png) [@hustlertwo](https://forum.choiceofgames.com/u/hustlertwo)\
**Post date:** [February 17, 2022, 10:55am UTC](https://forum.choiceofgames.com/t/how-to-add-random-chances-for-your-game/114263/7 "2022-02-17T10:55:29Z")

</div>

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.

```nohighlight
*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

```
