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!
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