# Using goto\_scene and variables

**URL:** <https://forum.choiceofgames.com/t/using-goto-scene-and-variables/15714>\
**Category:** ChoiceScript Help\
**Created:** [March 16, 2016, 12:09pm UTC](https://forum.choiceofgames.com/t/using-goto-scene-and-variables/15714 "2016-03-16T12:09:37Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kelvin](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/kelvin/32/8950_2.png) [@Kelvin](https://forum.choiceofgames.com/u/Kelvin)\
**Post date:** [March 16, 2016, 12:09pm UTC](https://forum.choiceofgames.com/t/using-goto-scene-and-variables/15714/1 "2016-03-16T12:09:37Z")

</div>

Is it possible to use \*goto\_scene (variable)? An example of this would be;

\*temp variable1 “scene4”  
\*goto\_scene “${variable1}”

The text file’s name would read “scene4.txt”.

Obviously this makes it harder than it has to be but in my game the scenes will be in a random order. I’ve solved this with a ton of if commands but I was curious.

Please note. I am not having trouble with the randomization of the scenes, I have all of that figured out.

Ex:  
\*if variable1 = “scene”  
-\*goto\_scene scene  
\*if variable1 = “scene2”  
-\*goto\_scene scene2  
…  
\*if variable2 = “scene”  
-\*goto\_scene scene  
Etc. etc. …

---

<div class="post-metadata">

**Author:** ![leo](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/leo/32/113837_2.png) [@leo](https://forum.choiceofgames.com/u/leo)\
**Post date:** [March 16, 2016, 12:52pm UTC](https://forum.choiceofgames.com/t/using-goto-scene-and-variables/15714/2 "2016-03-16T12:52:29Z")

</div>

Judging by your example I would say it’s probably possible, but generally what I do in that case would be a text variable like

\*if variable1= “leftdoor”  
-\*goto\_scene leftdoorscene

I’m not sure why you would need to name it the particular scene name. I would find it confusing personally, but if it works for you then I don’t see why not

---

<div class="post-metadata">

**Author:** ![Nocturnal\_Stillness](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/nocturnal_stillness/32/100414_2.png) [@Nocturnal\_Stillness](https://forum.choiceofgames.com/u/Nocturnal_Stillness)\
**Post date:** [March 16, 2016, 1:06pm UTC](https://forum.choiceofgames.com/t/using-goto-scene-and-variables/15714/3 "2016-03-16T13:06:40Z")

</div>

You can do that without variables now.

\*goto\_scene chapter\_one label\_name

Would send the player to chapter\_one and to the name of the label you mention.

---

<div class="post-metadata">

**Author:** ![Eiwynn](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/eiwynn/32/221334_2.png) [@Eiwynn](https://forum.choiceofgames.com/u/Eiwynn)\
**Post date:** [March 16, 2016, 1:07pm UTC](https://forum.choiceofgames.com/t/using-goto-scene-and-variables/15714/4 "2016-03-16T13:07:20Z")

</div>

In using the goto\_scene command you may need to make sure the variable is always defined for the script to work. I’m still learning but if at anytime the variable is not defined the script would crash (i think)

---

<div class="post-metadata">

**Author:** ![Hanon\_Ondricek](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/hanon_ondricek/32/95886_2.png) [@Hanon\_Ondricek](https://forum.choiceofgames.com/u/Hanon_Ondricek)\
**Post date:** [March 16, 2016, 1:42pm UTC](https://forum.choiceofgames.com/t/using-goto-scene-and-variables/15714/5 "2016-03-16T13:42:26Z")

</div>

I think there used to be a “gotoref” command, but it’s easier now than I think you’re making it - in the 2nd page (Advanced Choicescript) in the documentation:

> Goto a label by name:  
> \*temp superpower “invisibility”  
> Your super power is:  
> \*goto {superpower}  
> flight!  
> \*finish  
> \*label invisibility  
> invisibility.

So if you declare a variable \*create magicscene “pooloftears”, \*goto {magicscene} will go to pooloftears. If later you \*set magicscene “corridorofdoors” it will change {magicscene} to that.

I haven’t used this, but this seems to be the way to do it from the documentation. You could, of course, use a random to vary the scene.

In the wiki there’s a \*goto\_random\_scene command which lets you list a number of scenes the text can split to. Limitation of this is if you recurse it will pick a random scene each time and won’t re-use them. If the random scene list is exhausted, it falls out to the next scene instead of picking a random one from the list.

---

<div class="post-metadata">

**Author:** ![Kelvin](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/kelvin/32/8950_2.png) [@Kelvin](https://forum.choiceofgames.com/u/Kelvin)\
**Post date:** [March 16, 2016, 3:31pm UTC](https://forum.choiceofgames.com/t/using-goto-scene-and-variables/15714/6 "2016-03-16T15:31:49Z")

</div>

@Hanon_Ondricek I swear if this is true… I spent an hour on this and thought of this but decided that it wasn’t worth trying because it didn’t seem like it would work.

I’m away from home but I will try it when I get home.

---

<div class="post-metadata">

**Author:** ![Maxmansung](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/maxmansung/32/6630_2.png) [@Maxmansung](https://forum.choiceofgames.com/u/Maxmansung)\
**Post date:** [March 16, 2016, 7:14pm UTC](https://forum.choiceofgames.com/t/using-goto-scene-and-variables/15714/7 "2016-03-16T19:14:58Z")

</div>

Damn, I just wrote exactly what @Hanon_Ondricek has already told you. Sorry I read this post hours ago but wanted to test the code before I replied.

Just make sure you leave out the **$** sign when you write the variable for:

\*goto {variable}

and it will work fine

---

<div class="post-metadata">

**Author:** ![Kelvin](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/kelvin/32/8950_2.png) [@Kelvin](https://forum.choiceofgames.com/u/Kelvin)\
**Post date:** [March 16, 2016, 8:57pm UTC](https://forum.choiceofgames.com/t/using-goto-scene-and-variables/15714/8 "2016-03-16T20:57:05Z")

</div>

Ok thank you so much! I can’t believe I tried everything but that.

Tell me when your next update comes out for the followers I can’t wait to see where this goes. And again if any of you need any help don’t be afraid to ask!
