# What else can \*rand pick up?

**URL:** <https://forum.choiceofgames.com/t/what-else-can-rand-pick-up/854>\
**Category:** Game Development\
**Created:** [November 6, 2012, 4:22pm UTC](https://forum.choiceofgames.com/t/what-else-can-rand-pick-up/854 "2012-11-06T16:22:43Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![bluepencil](https://avatars.discourse-cdn.com/v4/letter/b/ac91a4/32.png) [@bluepencil](https://forum.choiceofgames.com/u/bluepencil)\
**Post date:** [November 6, 2012, 4:22pm UTC](https://forum.choiceofgames.com/t/what-else-can-rand-pick-up/854/1 "2012-11-06T16:22:43Z")

</div>

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”

[…]

---

<div class="post-metadata">

**Author:** ![CJW](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/cjw/32/111787_2.png) [@CJW](https://forum.choiceofgames.com/u/CJW)\
**Post date:** [November 6, 2012, 4:26pm UTC](https://forum.choiceofgames.com/t/what-else-can-rand-pick-up/854/2 "2012-11-06T16:26:23Z")

</div>

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
${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.

---

<div class="post-metadata">

**Author:** ![bluepencil](https://avatars.discourse-cdn.com/v4/letter/b/ac91a4/32.png) [@bluepencil](https://forum.choiceofgames.com/u/bluepencil)\
**Post date:** [November 6, 2012, 5:11pm UTC](https://forum.choiceofgames.com/t/what-else-can-rand-pick-up/854/3 "2012-11-06T17:11:04Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![CJW](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/cjw/32/111787_2.png) [@CJW](https://forum.choiceofgames.com/u/CJW)\
**Post date:** [November 6, 2012, 5:15pm UTC](https://forum.choiceofgames.com/t/what-else-can-rand-pick-up/854/4 "2012-11-06T17:15:00Z")

</div>

\*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.

---

<div class="post-metadata">

**Author:** ![andymwhy](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/andymwhy/32/34396_2.png) [@andymwhy](https://forum.choiceofgames.com/u/andymwhy)\
**Post date:** [November 6, 2012, 5:57pm UTC](https://forum.choiceofgames.com/t/what-else-can-rand-pick-up/854/5 "2012-11-06T17:57:42Z")

</div>

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  
\*return  
\*if breakfast = 2  
smoked mackerel  
\*return  
\*if breakfast = 3  
\*toast and marmalade  
\*return

//etc.

(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.

---

<div class="post-metadata">

**Author:** ![lordirishdas](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/lordirishdas/32/381_2.png) [@lordirishdas](https://forum.choiceofgames.com/u/lordirishdas)\
**Post date:** [November 6, 2012, 6:19pm UTC](https://forum.choiceofgames.com/t/what-else-can-rand-pick-up/854/6 "2012-11-06T18:19:46Z")

</div>

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
 *return
*elseif (breakfast=2)
 smoked mackerel
 *return
*else (breakfast=1)
 toast and marmalade
 *return

```

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

---

<div class="post-metadata">

**Author:** ![AlexCosarca](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/alexcosarca/32/68977_2.png) [@AlexCosarca](https://forum.choiceofgames.com/u/AlexCosarca)\
**Post date:** [November 7, 2012, 7:09am UTC](https://forum.choiceofgames.com/t/what-else-can-rand-pick-up/854/7 "2012-11-07T07:09:06Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![andymwhy](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/andymwhy/32/34396_2.png) [@andymwhy](https://forum.choiceofgames.com/u/andymwhy)\
**Post date:** [November 7, 2012, 4:01pm UTC](https://forum.choiceofgames.com/t/what-else-can-rand-pick-up/854/8 "2012-11-07T16:01:31Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![AlexCosarca](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/alexcosarca/32/68977_2.png) [@AlexCosarca](https://forum.choiceofgames.com/u/AlexCosarca)\
**Post date:** [November 7, 2012, 4:41pm UTC](https://forum.choiceofgames.com/t/what-else-can-rand-pick-up/854/9 "2012-11-07T16:41:21Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![andymwhy](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/andymwhy/32/34396_2.png) [@andymwhy](https://forum.choiceofgames.com/u/andymwhy)\
**Post date:** [November 7, 2012, 5:47pm UTC](https://forum.choiceofgames.com/t/what-else-can-rand-pick-up/854/10 "2012-11-07T17:47:13Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![lordirishdas](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/lordirishdas/32/381_2.png) [@lordirishdas](https://forum.choiceofgames.com/u/lordirishdas)\
**Post date:** [November 7, 2012, 7:46pm UTC](https://forum.choiceofgames.com/t/what-else-can-rand-pick-up/854/11 "2012-11-07T19:46:28Z")

</div>

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.
