Question

I'm making a batch text adventure (because it's the easiest language to do so in, requiring barely any coding experience) and I want to know if there is a way to make dynamic gotos or labels.

For example, I have a dynamic health and energy system which displayes diferent health bars, depending on the health variable which is aquired from a save file on the C:/ drive.

This requires quite a bit of code, and it would be much easier if I could just call a function.

As an alternative, I'd like to have a a dynamic goto. What I mean is a variable, and then a goto function.

:foo
set currentlbl="foo-"
echo Hello!
goto foo2

:foo-
echo %test%
pause
exit

:foo2
if "test"=="chizzits" set test2="derp"
if "test"=="chuzzits" set test2="herp"
goto %currentlbl%

Unfortunately, this doesn't work, as goto commands do not recognize variables. Is there a way past this?

Was it helpful?

Solution

Yes they can, remove the quotes in the set command, or place quotes in the label.

set currentlbl=foo-
:foo-

or

set currentlbl="foo-"
:"foo-"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top