Mentioning a Choice in the Text?


#1

Hi! I just got into coding using ChoiceScript, and I’m getting the hang of some of it. But I was wondering…

Say there is a choice where the player can pick a pet and name it. In later scenes, it is possible to refer to which specific pet they chose in the text (not an option)? Like if they chose a cat, then in a paragraph I write about him petting the cat/dog/insert pet here. Is that possible without having to write different scenes for just that one word?


#2

Absolutely! Basically, when you *create a variable at the beginning, and then later *set the value, all you have to do is type ${variablename} and the value of that variable will display.


#3

Yep

*create pet "none"

What type of pet do you have?

*choice
    #Cat
        *set pet "cat"
    #Dog
        *set pet "dog"

You pet your ${pet}.

If you only plan to use it once just use a temp variable instead.


#4

Thanks so much for the answer! It’s not leading to the next scene, though? For example, this is my choice I had before:

*choice
  #Be polite.
    *set social +5
  #Be suspicious. The Ministry must have found out, and sent their best wizard to deal with you!
    *set oblivious -5
  #Drop your eyes to the ground and nod silently.
    *set social -5
*goto scene1

*label scene1
Which pet would you like?
*choice
  #Cat
    *set pet "cat"
  #Dog
    *set pet "dog"
*goto scene2

*label scene2
You pet your ${pet}.

(Or I tried the:)
*choice
  #Be polite.
    *set social +5
  #Be suspicious. The Ministry must have found out, and sent their best wizard to deal with you!
    *set oblivious -5
  #Drop your eyes to the ground and nod silently.
    *set social -5
*goto_scene pet

(And in a txt file I called "pet")
Which pet would you like?
*choice
  #Cat
    *set pet "cat"
  #Dog
    *set pet "dog"
*goto_scene paragraph

(In a file called paragraph)
You pet your ${pet}.

(I see that the reply is not adding spaces. I have 2 spaces in front of #, and 4 spaces in front of *)


#5

Oh sorry, I assumed you knew how choice commands work. You need to have a goto or finish in each branch, unless you use the fakechoice command. So

Which pet would you like?

*fake_choice
  #Cat
    *set pet "cat"
  #Dog
    *set pet "dog"
*goto scene2

alternatively

*choice
  #Cat
    *set pet "cat"
    *goto scene2
  #Dog
    *set pet "dog"
    *goto scene2

Also

How to format your code so it can be seen on the forum.

Paste code into window.
Highlight all of the code.
Click the preformatted text button. (It looks like </> and is next to the quote one and on the same bar as the other formatting and smilies choice.)
Click reply.


#6

Thanks so much, that worked! It’s really taken a weight off my mind. :slight_smile: I’m sorry I didn’t post correctly, thank you so much for the link.