What else can *rand pick up?

Okay, so *rand allows us to assign random numbers to a variable (which should have been created first, aha) but can it handle expressions too?

Something like renpy’s
$ randdesc = renpy.random.choice([‘whomps’, ‘totally wails on’, ‘staggers’])

Is it possible for me to get *rand to pick something from a list, so at the very least just for something like

“‘A {adj1} {noun1} is no more ${adj2} than anything else.’”

I won’t have an obscenely long block going

*label get_random_word
*if adj1_r = 1
*set adj1 = “pretty”
*if adj1_r = 2
*set adj1 = “warm”
*if adj1_r = 3
*set adj1 = “silent”
*if adj1_r = 4
*set adj1 = “new”
*if adj1_r = 5
*set adj1 = “lost”


1 Like

You’d have to use ref commands:

*rand var 1 3
*set randword "randword_"&var
*gotoref randword

*label randword_1
*set randword "Pretty"
*goto print_randword

*label randword_2
*set randword "Warm"
*goto print_randword

*label randword_3
*set randword "Silent"
*goto print_randword

*label print_randword

You could add further complexity to produce lists of nouns/adjectives etc, but you’d still have that “list” of configured values. There’s no way around that in raw choicescript.

1 Like

Ah! That’s quite a nifty process. Thanks a bunch.

If there is a *label get_randword it would still be the same if, instead of *goto, I use *return, right?

*return should only be used after using *gosub, which has the same effect as *goto, only it allows you to (and expects you to) *return

Return will return you to the line AFTER the gosub was called, so in my above situation there’s no need for it?

But you could most definitely create a system of sorts that allows you to generate a random word, return the value and then be recalled as many times as you need words.

Breakfast at Blackraven is randomised each day.

//Each day I start with
*rand breakfast 1 30
//Then I have text:
You take your breakfast of
*gosub breakfast_choice
and find a table to sit and eat.

//Under breakfast_choice
*label breakfast_choice
*if breakfast = 1
a bowl of porridge
*if breakfast = 2
smoked mackerel
*if breakfast = 3
*toast and marmalade


(Spaces in the correct place, naturally) With a bit of playing around, I have a random drink as well and different lunch menu’s too.

1 Like

I use rand often so have found that it is best to place the order highest to lowest or you may run into a problem with it not running correctly so in the above example I would.

*if (breakfast=3)
 a bowl of porridge
*elseif (breakfast=2)
 smoked mackerel
*else (breakfast=1)
 toast and marmalade

I am not a programmer but have found I have a lot less issues with the order in this manner.

1 Like

@lordirish, what issues exactly did you find while putting them in an ascending order?

I haven’t come across any issues with having the order ascending. The only issues I could potentially see are where you are increasing a variable by +1 each time (not random) and forget to *finish or *return at the end. You’d have results for (example) breakfast = 3 and breakfast = 4 both appearing in your game.

By the way, instead of using *elseifs and *elses, you could just write *if conditions (which don’t have to end in a *goto if there’s no *elseif or *else after them) and just write a *return at the end of the whole subroutine; that’d save some lines.

Very true @AlexCosarca - in ‘The Race’ I used many *elseifs and *elses before discovering that *ifs could be used alone to speed up the coding process. That’s one of the great things about coding - you’re always learning new tricks and shortcuts!

A good example of this that I am using for ‘Blackraven’ is adding conversation parts based on your past choices.

For example, you might make a scene and cry over spilt milk in the canteen early in the game (*set cry_scene true), instead of just shrugging and cleaning it up (*set cry_scene false).

Later, when talking to someone, you could have the code:

You meet Bob, a tall man with dark hair.
*if cry_scene true
__He laughs at you and tells you he remembers when you spilt the milk in the canteen.
__You shake his hand and ask him if he has any cigarettes for sale.

You can add other optional text parts in a similar way that will only become active if you chose that path earlier in the game.

When i would program it descending from 1 to whatever number it would hang and seem to be stuck on one number. It has happen several times in different codes. Once I started counting down highest to lowest never again hit that bug.