Randomness from a "deck"

Does anybody here know how to make it so that random scenes play after a certain scene (Which as said in the title would “draw” from a “deck” of 4 possibilities) So for example: I’m on Scene 1, and the next scenes can be 2A, 2B, 2C and 2D, how would I make it so that one of them is picked and shown randomly, and the others are left out entirely?

2 Likes

You can make a variable for scene variation, then use the *rand command, then use if statements. Something like this:

*rand scenevariation 1 2
*if scenevariation = 1
*goto scenea
*if scenevariation = 2
*goto sceneb

For your case, just replace the 2 at the *rand command with 4 and do 4 if statements for each variation. Hope this helps, good luck! (also feel free to correct me if i’m wrong, i’m also kinda a newbie)

3 Likes

I think this can help, or somehow serve as reference:

8 Likes

^This, except use the rand command at least 1 page break back before you need it. (I’d even set it right at the start of the game so the game is just set and out of the way.) If you use it here and people check the stat menu on starting the new scene, it can sometimes cause the rand command to reroll causing the scene to keep resetting.

2 Likes

Ah I see, I actually used that kind of “bug” to my advantage in some games where even if you did everything perfectly there was still an element of luck (Parenting Simulator).

3 Likes

Heresy! Burn him at the stake!

Yeah, that’s actually pretty fair, though I thought I had added page breaks to all (or at least most) of the spots where hitting the stat screen could reroll your results in a manner that players could actually see. And my own random scene generator for TPS worked pretty much the same way as described above, and was quite handy.

4 Likes

Haha, yeah I leaned about the rand the hard way when writing Dragon Chronicles which has RNG affected scenes, battles, loot drops etc. If you don’t separate the roll from the result the player definitely sees it. Best case the player can keep “rolling” via the stat screen until get the scene/result they want like you’re saying. Worst case it annoys people if they’re reading a scene and it suddenly changes when they’ve checked the stat screen to decide on what choice to take, or if you have other variables being triggered by the scene selection change it causes the game to crash spectacularly in new and fun ways you never expected :grin: (It took me so long to completely debug that game! That’s why I have a thing about warning people about the rand reroll effect which played a significant part in the problems I had with it.)

3 Likes
*create next_scene 1
*comment 1: 2A
*comment 2: 2B
*comment 3: 2C
*comment 4: 2D

...

*rand next_scene 1 4

*if (next_scene = 1)
  *set scene_number "2A"
(etc)

*page_break
*comment the page break is very important
*comment you can also use a *choice or *fake_choice
*comment just separate the roll from the result somehow

*goto_scene ${scene_number}

What you’ve got here actually isn’t “deck” randomisation – it’s just the normal kind. If you want to make it possible to visit the other three scenes later on, but take out any scenes you’ve already done, the code becomes much more complicated.

1 Like

It’s not too bad unless you’re running dozens of different random scene chances that can’t repeat. (In which case it’s just annoyingly repetative in the code, at least the way I use it. There may be a better way.) Using your example, if it was the 3rd time I’d used a random scene I just throw in something like:

*label roll_scene 

*rand next_scene 1 4


*page_break
*comment the page break is very important
*comment you can also use a *choice or *fake_choice
*comment just separate the roll from the result somehow

*if (next_scene = 1)
   *if ((scene1 = 1) or (scene2 = 1))
      *comment causes a reroll
      *goto roll_scene

   *set scene3 1
   *comment if the scene hasn't been hit yet it sets the scene3 number to "1" and proceeds to the right file.
   *goto scene_number_3


(etc for each next_scene number)


The other way is to just do these rolls for each scene setup in the startup file (so not have the goto_scene or page breaks in there and just set the scene value), so when you come to the branch later in the game you get a branch like this:

*if scene3 = 1
   *goto_scene 1
*if scene3 = 2
   *goto_scene 2 
(etc)

(I just kind of like this as it keeps it all tidier and less prone to bugging out if a mistake is made in the code being written up at separate points, but either works :slight_smile: .)

5 Likes

As long as you don’t want to ‘draw’ any individual scene more than once per playthrough, it’s as simple as

*goto_random_scene
    2a
    2b
    2c
    2d

used multiple times. *goto_random_scene automatically prevents you from going to the same scene twice.

6 Likes

Alrighty, I assume that the way to make it so that you can only get a certain scene if you have a certain stat would be as simple as

*rand Scenevariation 1 3

*if Leadership > 60

*rand Scenevariation 1 4

Right?

You learn a new choicescript command every day.

Fuck me that would’ve been useful for A Kiss from Death.

3 Likes

:astonished: so this command chooses one of the scenes at random and ehen reused later in game makes sure no scene is used twice?

What if you add 2e later?

2 Likes

Whaaaaaat? I mean, it wouldn’t necessarily have worked as well for Parenting since the random segments weren’t actual ‘scenes’ in the Choicescript meaning of the word, but I am still floored that there’s a command that covers this. Could be handy in certain circumstances.

1 Like

You could make something like this if you want certain scenes to be picked by *goto_random_scene ONLY if you’re on a specific part of the story:

In startup
*create current_scene "chapter one"
*create random_scene1 "2a"
*create random_scene2 "2b"
*create random_scene3 "2c"
*create random_scene4 "2d"
*create random_scene5 "2e"
-------------------------
In another scene
*label scene_check
*if (current_scene = "chapter two")
    *set random_scene1 "2f"
    *set random_scene2 "2g"
    *set random_scene3 "2h"
    *set random_scene4 "2i"
    *set random_scene5 "2j"
    *goto scene_pick
*else
    *goto scene_pick
*comment endif/
*label scene_pick
*goto_random_scene
    {random_scene1}
    {random_scene2}
    {random_scene3}
    {random_scene4}
    {random_scene5}
2 Likes

I might be misunderstanding you, but you don’t need to switch scenes when using the method Jacic described. I discovered this method while coding a few weeks ago, and I can tell you that it’s possible to create an entirely random game without anything repeating or switching scenes. This is mainly why I don’t feel the need to use *goto_random_scene

I also was able to do that without *goto_random_scene for A Kiss from Death but it would have made things a lot easier. A random non-replaceable outcome is really valuable and you don’t realize how much you miss it until it’s not there.

1 Like

That’s understandable, the only problem I have with that command is that it creates unnecessary scenes. Everyone has their own preference. However, if one can achieve the same effect by adding a little more code, then I don’t see any reason not to.

Previously, you said that the code would become much more complicated. Depending how you do it, you can make it simpler. Just like the second example Jacic suggested. A few more *if commands, variables, and you’re done.