Help with Choicescript if and variables


#1

I need help with some *if and variables
Basically what i have is

#Coffee seems like the only fuel you can consume here, I'll take it.
    *temp var "Coffee"
    *goto intro
  #Tea helps me calm down, I'll have a cup of it.
    *temp var "Tea"
    *goto intro
  #Water. Need to be hydrated.
    *goto intro
    *temp var "Water"
  #Nothing really.
    *temp var "Nothing"
    *goto intro

And then i later on i have:

*if var = "Coffee"

Coffee has come.
*goto questions

*if var = "Tea"

Tea has come.
*goto questions

*if var = "Water"

Water has come.
*goto questions

*if var = "Nothing"

Nothing has come.
*goto questions

But when i test it out it appears an error like “invalid indent, expected at least one line in ‘if’ true block”

Can someone help me out?


#2

You can do this:

*choice
   #Coffee seems like the only fuel you can consume here, I'll take it.
      Coffee has come.
      *goto questions
   #Tea helps me calm down, I'll have a cup of it.
      Tea has come.
      *goto questions
   #Water. Need to be hydrated.
      Water has come.
      *goto questions
   #Nothing really.
      Nothing has come.
      *goto questions

If you could copy the entire context of this bit, we could help further. but in short:
*temp
is a command if you need a variable only for one scene.
For example:

*temp drink ""
What do you want to drink?
*choice
   #Coffee seems like the only fuel you can consume here, I'll take it.
      *set drink "coffee"
      *goto questions
   #Tea helps me calm down, I'll have a cup of it.
      *set drink "tea"
      *goto questions
   #Water. Need to be hydrated.
      *set drink "water"
      *goto questions
   #Nothing really.
      *set drink "nothing"
      *goto questions

*label questions
@{(drink = "nothing") You don't drink anything.| You drink ${drink}.}

The bit with the @ is multireplace, allowing to have multiple variants of a sentence without doing *if


#3

Okay i’ll try it!
I feel like the second one might work better because in the middle of choosing a drink and getting the drink there is a scene that takes place. But i think i know how to fix it now.
Thank you!


#4

It depends:
does the drink come up at another time in the same scene?
If not you don’t need to make it a variable.


#5

Yes it does. And the attitude of the character also changes depending on the drink.


#6

Ahh. alright. Yeah, then the second works better probably. You could also combine things like this:

*temp drink ""
What do you want to drink?
*choice
   #Coffee seems like the only fuel you can consume here, I'll take it.
      You drink coffee.
      *set drink "coffee"
      *goto questions
   #Tea helps me calm down, I'll have a cup of it.
      You drink tea.
      *set drink "tea"
      *goto questions
   #Water. Need to be hydrated.
      You drink water.
      *set drink "water"
      *goto questions
   #Nothing really.
      You drink nothing.
      *set drink "nothing"
      *goto questions

*label questions

#7

Yeah okay, thank you so much for the help!
I think i managed thanks to you, i’ll update this if i keep having problems. :smiley:


#8

Godspeed to you :smiley:


#9

Okay having the same message though i still don’t know why.

My code is this:

*if drink = "coffee" 
You take a sip from your coffee.
*goto questions

*if drink = "tea" 
You take a sip from your tea.
*goto questions

*if drink = "water"
You take a gulp from your water.
*goto questions

*if drink = "nothing" 
You stand there.
*label questions

But when the drink is coffee it works well, but the rest of the drinks it goes into the same error.


#10

It might be that you need an indentation after every *if line? I can’t tell if it’s just that it’s hard to indent on the forum or if you aren’t indenting in the code. I can see you have indentations on the first block of code example you put in, but not the second.


#11

No i understood you.
And i did it.
It actually worked!
Thank you for the help!
I’ll keep updating if i have more problems.


#12

you don’t need and *if statement in this case.
*if and its siblings are more for stuff like this:

*choice
   #game1
      *if (rival = "Walter")
      You should be aware that this is the game that will have you face Walter.
      *goto game1
      *else
      At least you won't face your rival in this.
      *goto game1
   #game2
      *if (rival = "Hank")
      You should be aware that this is the game that will have you face Hank.
      *goto game1
      *else
      At least you won't face your rival in this.
      *goto game1
etc

#13

Oooooh
Sorry, since i’m kind of new to this.
But i get what you mean. Thank you for the help!
:slight_smile:


#14

No worries :slight_smile:
Oh, also there’s
*elseif

goes like this:

*if (possibility 1)
   stuff
   *goto more
*elseif (possibility 2)
   stuff
   *goto more
*else
   stuff
   *goto more

*else covers the variables not used for if/elseif in that body

#15

That might be useful later on.
Thank you once again!


#16

Okay one more problem.
I’m sorry for being such an amateur about this.

*if drink = "tea" 
  You sip the tea.
  *goto questions

*if drink = "water"
  You sip the water.
  *goto questions

Now the tea works well and all, but the water one doesn’t show the “you sip the water” part. It just goes to the label questions.


#17

Try this:

*if drink = "tea" 
  You sip the tea.
  *goto questions
*elseif drink = "water"
  You sip the water.
  *goto questions
*elseif drink = "coffee" 
  You sip the tea.
  *goto questions
*else
  You drink nothing.
  *goto questions

But as said, having an if/elseif/else seems unnecessary here from what I can see.

*choice
   #Coffee seems like the only fuel you can consume here, I'll take it.
      You drink coffee.
      *set drink "coffee"
      *goto questions
   #Tea helps me calm down, I'll have a cup of it.
      You drink tea.
      *set drink "tea"
      *goto questions
   #Water. Need to be hydrated.
      You drink water.
      *set drink "water"
      *goto questions
   #Nothing really.
      You drink nothing.
      *set drink "nothing"
      *goto questions

will do the trick at this bit as well.
if/elseif/else should only come into play once the text differs greatly further down the line.

like

*if ((drink = "tea") or (drink = "coffee"))
   You spill the ${drink} over Hank. He screams. Bloody Hell that must have been hot.
   *goto whoops
*elseif (drink = "water")
   You spill the ${water} over Hank. Whoops.
   *goto whoops
*else
   *goto nowhoops

#18
*if drink = "coffee" 
  You drink the coffee.
  *goto questions

*elseif drink = "tea" 
  You sip the tea. 
  *goto questions

*elseif drink = "water"
  You sip the water. 
  *goto questions

*else
  You stand there.
  *goto questions

That’s what i put. But now if i choose water, it shows the “nothing” result.


#19

ah bother, my mistake.
add () around the variables. like
*if (drink = “water”)


#20

Oooh okay, let me see…