Question about making branches

hello! so i’ve been trying to learn choicescript these past few days, and wanted to try my hand at making different branches. however, when i try to choose an option, the resulting text becomes like this, for every choice:

Summary

image

this is embarrassing but what exactly am i doing wrong here?

my code looks like this:

*choice
	#a man
		*set gangel "michael"
		*goto gangel_chosen
	#a woman
		*set gangel "gabriel"
		*goto gangel_chosen
	#you're not sure...
		*set gangel "uriel"
		*goto gangel_chosen
*label gangel_chosen
*if (gangel = "a man")
		*goto guardian_chosen1
*if (gangel = "a woman")
		*goto guardian_chosen2
*if (gangel = "you're not sure...")
		*goto guardian_chosen3
*label guardian_chosen1
abcd
*label guardian_chosen2
efg
*label guardian_chosen3
hijk

I’m not sure what you’re trying to do here? You cannot use “gangel” to check the previous choice, because you’ve just used that variable to store the name. So if you want to later on be able to know which angel the player got, you should check by name.

Therefore, none of your conditionals are actually being entered (gangel is never any of the values you look for, at this point) so I guess that what’s happening is that the flow resumes at the first label and then just goes down from there.

Here’s what I would try:

*choice
	#a man
		*set gangel "michael"
		*goto gangel_chosen
	#a woman
		*set gangel "gabriel"
		*goto gangel_chosen
	#you're not sure...
		*set gangel "uriel"
		*goto gangel_chosen

*label gangel_chosen
Congratulations, you have your own guardian angel now! 

*if (gangel = "michael")
		*goto guardian_chosen1
*if (gangel = "gabriel")
		*goto guardian_chosen2
*if (gangel = "uriel")
		*goto guardian_chosen3

*label guardian_chosen1
abcd
*goto resume

*label guardian_chosen2
efg
*goto resume

*label guardian_chosen3
hijk
*goto resume

*label resume
This is where everyone gets the same text again.

Note that you need to have *goto inside the labels, else if you send the player to the first label they will get the second and third as well. Also note that this only makes sense if you’re going to have some sort of text that remains the same regardless of choice inside *label gangel_chosen; otherwise, you can just put the *goto commands for each angel inside the choice itself, which is much simpler.

You can also write whatever goes inside *label guardian_chosen1, *label guardian_chosen2, and *label guardian_chosen3 inside the if, rather than have the goto. This is what I would do if I were writing this scene, myself, but it’s a matter of preference.

Edit: Also forgot to say that you can have that structure as if…elseif…else, rather than if…if…if…. It’s not very important, but we programmers are just picky like that. :stuck_out_tongue_winking_eye:

6 Likes

thank you! i will try this out when i get home!

1 Like

Some bit of descriptions on what happened in your code:

ChoiceScript parse your code line by line. For example, this code:

*label tex
Abc
Def
Ghi

Will result to :Abc Def Ghi. And label by itself does nothing, so:

*label tex
Abc
*label tex2
Def
*label tex3
Ghi

Will still give you: Abc Def Ghi.


In relation to above behavior, *goto command doesn’t skip the line by line parsing behavior. As such:

*goto tex

*label tex
Abc
*label tex2
Def
*label tex3
Ghi

Will give you: Abc Def Ghi. Protip: with above template, try switching *goto tex with tex2 and tex3.


Finally, on variable assignment. Here is the syntax:

*set [var] [value]

Where [var] is the varible’s name and [value] is the value you assign to it.

To do its conditional check:

*if [var] = [value]
   Code to parse if check is passed

What you did wrong is you’re putting the text of the #choice instead of the value the var is assigned in the checks. Consider this:

*if gangel = "a man"

Vs.

*if gangel = "michael"
4 Likes

thank you so much for this!

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.