Not sure how to set this code up

I’m not sure if I’ve set up the *if statements correct.

*choice
	#"I wanted to explore the area surrounding the camp" 
		*if crush Ike then +5 ikefriendship 
		*if crush Rhys then +5 rhysfriendship 
		*if crush Tibarn then +5 tibarnfriendship 
		*if crush Gatrie then +5 gatriefriendship 
		"That sounds exciting." ${crush} said. "Yeah and then it got even more exciting when that guy decided to try to 			attack me." You said. "I was gald when you came to save me. I don't think I would have been able to make it out 			by myself." "It was nothing really but I'm glad you're ok." The two of you make it back to the camp without any 			other excitement happening.
		*finish

Thanks for the help

*choice
  # I Wanted to explore the area surrounding the camp)
    *if crush_ike
      *set ike_friendship ike_friendship + 1
      *goto carry_on
    *elseif crush_rhys
      *set rhys_friendship rhys_friendship + 1
      *goto carry_on
    *else
      *bug "Impossible crush. Woops! That shouldn't have happened."

*label carry_on

EDIT: Added *goto/label combo, as that’s the default.

Also, it sounds like you could stand to (re)read the basic tutorial material: https://www.choiceofgames.com/make-your-own-games/choicescript-intro/

1 Like
*choice 
  #"I wanted to explore the area surrounding the camp" 
    *if crush = "Ike"
      *set ikefriendship +5
      *goto crush_answers
    *if crush = "Rhys"
      *set rhysfriendship +5
      *goto crush_answers
  #Other dialog option.
    *goto other_label
*label crush_answers
"That sounds exciting." ${crush} said. 
*line_break
"Yeah and then it got even more exciting when that guy decided to try to attack me." You said. "I was gald when you came to save me. I don't think I would have been able to make it out by myself." 
*line_break
"It was nothing really but I'm glad you're ok." 
*line_break
The two of you make it back to the camp without any other excitement happening. 
*finish

My option and previous poster’s option require different types of variables for defining the crush.
My option requires a string variable, so it goes like this:

  1. *create crash “” when creating the variable;
  2. *set crash “Name of your crash” when the MC “crashes”.

For previous poster’s option:

  1. *create crush_ike false and so on for every potential RO when creating variables;
  2. *set crush_ike true when the MC “crashes”.

FWIW using string comparisons is much more prone to human error.
It’s easy to make a mistake like, say: *set my_crush “ikr” which you won’t necessarily notice right away (and this where if/elseif/else:bug comes in handy!). With boolean checks it’s either False, True or the interpreter complains immediately.

Both ways are perfectly valid, and you should use whichever you’re comfortable with, of course. That said, when advising newcomers, I think these sorts of differences are worth highlighting.

1 Like

For the best result, IMO, you need to write all those conditions into their “mathematical sentence.”

Ok thanks for the helpI tried your suggestion but now when I test it I get the error message Non-existent variable ‘crush_ike’
This is in my startup

*create crush "?"

This is earlier in the same chapter

*choice
	#Ike
		*set crush "Ike"
		*goto paragraph13
	*selectable_if (rhysfriendship >60) #Rhys
		*set crush "Rhys"
		*goto paragraph13
	*selectable_if (tibarnfriendship >60) #Tibarn
		*set crush "Tibarn"
		*goto paragraph13
	*selectable_if (gatriefriendship >60) #Gatrie
		*set crush "Gatrie"
		*goto paragraph13

and what I changed the part I asked about originally too

*choice
	#"I wanted to explore the area surrounding the camp" 
		*if crush_Ike 
		*set ikefriendship +5  
		*goto answer
		*if crush_Rhys  
		*set rhysfriendship +5 
		*goto answer
		*if crush_Tibarn 
		*set tibarnfriendship +5 
		*goto answer
		*if crush_Gatrie
		*set gatriefriendship +5 
		*goto answer 
		*label answer
		"That sounds exciting." ${crush} said. "Yeah and then it got even more exciting when that guy decided to try to 			attack me." You said. "I was gald when you came to save me. I don't think I would have been able to make it out 			by myself." "It was nothing really but I'm glad you're ok." The two of you make it back to the camp without any 			other excitement happening.
		*finish

Thanks for the help

Now you nailed it!


As for the [crush] variable, there’re two ways to work around them.

  1. This is @CJW’s suggestion, by using different variables: [crush_ike], [crush_rhis], [crush_tibarn], [crush_gatrie].
    Yes, those are different variables and you need to *create them on “startup.txt.” They’ll be a boolean variable, meaning you want to do true/false instead of “Ike,” “Rhis,” “Tibarn,” or “Gatrie.”
  2. This is what I believe you’re going from your code example, by using single variable [crush].
    In this case, you want to switch the conditional checks into something like
*if crush = "Ike"
   Then this
*elseif crush = "Rhys"
   That one
*elseif crush = "Tibarn"
   No, not that one
*else
   Yes, that one

:exclamation: Beware: mind the capitalization. They’re CaSe SenSitiVE.

1 Like

I’m not sure if this has been asked before or not but I’m asking anyway. I’ve been getting the error message Invalid set instruction, no expression specified: crush for this code and was wondering what was wrong. I tried looking up the error message but couldn’t find anything.

*choice
	#Ike
		*set crush
		*goto paragraph15
	*selectable_if (rhysfriendship >70) #Rhys
		*set crush
		*goto paragraph15
	*selectable_if (tibarnfriendship >70) #Tibarn
		*set crush
		*goto paragraph15
	*selectable_if (gatriefriendship >70) #Gatrie
		*set crush
		*goto paragraph15

Thanks in advance

So in the startup file you probably will have to put

*create crush "false

And in your scenes …

*set crush true

2 Likes

What are you setting the crush variable to? You’ve told ChoiceScript you’re going to set the variable crush to a certain value… but there’s nothing in your sample to indicate what you want that value to be.

Try something like:

*choice
    #Ike
        *set crush "Ike"
1 Like

@amethyst please don’t make a new thread for every problem. Better if you keep them all in this thread (I have merged for you this time). Thanks!

1 Like

In general, code requires very strict formatting, so you should look at the tutorials and follow them exactly. It’s very important that no code can have two meanings, because the computer would have to pick one basically at random.

Here, the command to set a variable to a fixed value has three parts:
1.*set, to indicate you’re setting a variable
2.the name of the variable you’re setting
3.the value you’re setting it too
Then generally you want to end the line to signal you’re done so the computer knows not to look for a + and another value; you might be able to get around that using parenthesis but I haven’t checked because I’d recommend not doing that.

There’s multiple different ways to structure *set for different tasks, but they’re all equally strict. If you’re getting errors off a line right away it generally means you’ve made a mistake in following the rules for what you’re trying to do so that the line doesn’t match any rules and thus means nothing to the computer. You’ll probably solve it faster by going to the relevant wiki page and finding the example code for the thing you want to do then duplicating it rather than asking on the forum. These sorts of errors are pretty much like screwing up punctuation in prose; they happen all the time and are usually easy to fix if you check reference material.

Now, if that doesn’t help, or worse, the computer accepts a line but doesn’t do what you want it to, take that to the forum. Also, while error messages are useful don’t rely on them to be perfectly accurate; they’ll come at the point where it’s definitely impossible for the code to mean anything and may be some distance from the mistake.

3 Likes

@James_Marsh I have checked the tutorials or wiki pages for whatever my issue was but in some cases it’s either not exactly what the error was. In some cases I post to the forum as I wanted a fresh pair of eyes to look at it incase it was a simple error but I just keep missing it since I’ve been looking at the same thing for a while.