# Variable as goto label?

**URL:** <https://forum.choiceofgames.com/t/variable-as-goto-label/5448>\
**Category:** ChoiceScript Help\
**Created:** [October 6, 2014, 7:02pm UTC](https://forum.choiceofgames.com/t/variable-as-goto-label/5448 "2014-10-06T19:02:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![CptGoldie](https://avatars.discourse-cdn.com/v4/letter/c/eb9ed0/32.png) [@CptGoldie](https://forum.choiceofgames.com/u/CptGoldie)\
**Post date:** [October 6, 2014, 7:02pm UTC](https://forum.choiceofgames.com/t/variable-as-goto-label/5448/1 "2014-10-06T19:02:40Z")

</div>

I was wondering if i could use:  
\*goto StoryPointer  
at the end of a battle system, so i could essentially call that battle system from any point in my game, feed it the variables i have defined from that point in the story and when the battles over, return to the next page in the story. then i can call a new battle with new variables reflecting the new position in the story.

If you can’t have a redirecting goto command then the battle system can’t be re-usable as instead of advancing in the story, it will go back to the same place forming a loop.

the only fix i can think of, is adding a lot of if commands, checking what StoryPointer is current and then using that specific goto NAME.  
\*if StoryPointer = NAME1  
\*goto NAME1  
\*if StoryPointer = NAME2  
\*goto NAME2  
I really hope there’s a way to just use a ( goto Variable) to avoid having to use all that extra code.

---

<div class="post-metadata">

**Author:** ![FairyGodfeather](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/fairygodfeather/32/16709_2.png) [@FairyGodfeather](https://forum.choiceofgames.com/u/FairyGodfeather)\
**Post date:** [October 6, 2014, 7:08pm UTC](https://forum.choiceofgames.com/t/variable-as-goto-label/5448/2 "2014-10-06T19:08:01Z")

</div>

I don’t think you can use variables within a \*goto command. (I could be proven wrong though).

Could you use sub-routines and the return command? I’m not sure if they work if you’re going between scenes though.

> **[Gosub](https://choicescriptdev.fandom.com/wiki/Gosub)**
>
> ChoiceScript supports a simple form of subroutines. A subroutine is a section of code able to be accessed (using the\*gosub command) where& when required at many different points within the same scene file. This essentially negates the need to...

---

<div class="post-metadata">

**Author:** ![CptGoldie](https://avatars.discourse-cdn.com/v4/letter/c/eb9ed0/32.png) [@CptGoldie](https://forum.choiceofgames.com/u/CptGoldie)\
**Post date:** [October 6, 2014, 7:31pm UTC](https://forum.choiceofgames.com/t/variable-as-goto-label/5448/3 "2014-10-06T19:31:40Z")

</div>

yes that should work, i haven’t tested it but it sounds solid, i’ll change goto’s into gosub. thanks for the quick reply.

---

<div class="post-metadata">

**Author:** ![JimD](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/jimd/32/21672_2.png) [@JimD](https://forum.choiceofgames.com/u/JimD)\
**Post date:** [October 6, 2014, 9:43pm UTC](https://forum.choiceofgames.com/t/variable-as-goto-label/5448/4 "2014-10-06T21:43:05Z")

</div>

\*set a variable hold\_position. Before you send the reader to the battle code, record with hold\_position where you want to send the reader after the battle. At the end of the battle scene, use \*gotoref hold\_position.

For example:

\*set hold\_position “StoryPhaseTwo”  
\*goto BattleSequence

\*label BattleSequence  
\*comment fight fight fight  
\*gotoref hold\_position

\*label StoryPhaseTwo  
Story story story  
\*set hold\_position “NextStory”  
\*goto BattleSequence

\*label NextStory  
Blah blah blah  
\*finish

---

<div class="post-metadata">

**Author:** ![CJW](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/cjw/32/111787_2.png) [@CJW](https://forum.choiceofgames.com/u/CJW)\
**Post date:** [October 6, 2014, 10:53pm UTC](https://forum.choiceofgames.com/t/variable-as-goto-label/5448/5 "2014-10-06T22:53:19Z")

</div>

> **[Ref Commands](https://choicescriptdev.fandom.com/wiki/Ref_Commands)**
>
> The two ref commands (\*gotoref and\*setref ) are advanced ChoiceScript commands that allow further reference of variables by their names and values. They are essentially extensions of the\*set and\*goto commands. They perform exactly the same...
