Login
Remember
IF Answers
Ask a Question

# Printing a random sentence

0 votes
89 views
asked Aug 18 in Authoring by anonymous

Hello! I was wondering if it was possible in Quest to have the game print out a sentence compiled randomly of predetermined components?

Let's say for example's sake I was making a game where I would want the description of a TV screen to change every time the player looked at it. I want the description to be "X is doing Y to Z", where the words for X, Y, and Z are randomly chosen from a list of possible phrases. The choices for X could include "the dog", "the cat", and "the giraffe"; for Y, "is eating", "is chasing", and "is jumping on"; and for Z, "a man", "an apple", and "a car". So the description for the programme playing on the TV could be "The dog is chasing a car", or "The giraffe is eating a man", or "The cat is jumping on an apple", or any other combination - always different, but always in the same order.

Sorry for the convoluted explanation, but I hope you get what I mean! I don't think this should be too complicated or completely out of Quest's wheelhouse, but I just don't know how I can do it.

- quest

## 1 Answer

0 votes
answered Aug 18 by hegemonkhan (161 points)

if you can deal with code (or can figure out how to do this stuff in the GUI~Editor):

(I don't have the time now, but later I can give an answer via using the GUI~Editor)

the answer is using List~Dictionary Attributes and the Randomization Functions

http://docs.textadventures.co.uk/quest/guides/using_lists.html
http://docs.textadventures.co.uk/quest/functions/stringlistitem.html

http://docs.textadventures.co.uk/quest/using_dictionaries.html
http://docs.textadventures.co.uk/quest/functions/stringdictionaryitem.html

http://docs.textadventures.co.uk/quest/functions/corelibrary/diceroll.html
http://docs.textadventures.co.uk/quest/functions/getrandomint.html
http://docs.textadventures.co.uk/quest/functions/getrandomdouble.html
http://docs.textadventures.co.uk/quest/functions/corelibrary/randomchance.html

for example:

// pretend the list's items~Values are sentences and not words

as scripting:

    game.dialogue_list_1 = split ("hi; bye; okay; doh", ";")

as 'creation' tag:

    <game name="xxx">
      <attr name="dialogue_list_1" type="stringlist">
        <value>hi</value>
        <value>bye</value>
        <value>okay</value>
        <value>doh</value>
      </attr>
    </game>

for example, for 'whatever' Object's 'whatever' Verb:

    dialogue_selection = StringListItem (game.dialogue_list_1, GetRandomInt (0, ListCount (game.dialogue_list_1) - 1))
    msg (dialogue_selection)

String Dictionary Attributes are pretty much the same, except instead of using index numbers like lists do, you use a string

I'll help with using String Dictionaries later, I got to get off now... (didn't have much time at the moment to post, lol).

commented Aug 19 by Forktoss (1 point)
Thank you! I'm not too great with code, so I would be interested to hear how this works in the GUI editor as well, but this already clears up a few things. Thanks a lot!

## Related questions

- How does the {random} script work?
- Placing an object at random
- What script creates a link to a page?
- Help! I need to use a candle as a light source in rooms in my Quest text adventure game
- Quest Problem with "Get Input" in a loop

...