Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

batch - dynamic labels or functions

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?

like image 528
Poyo Avatar asked Feb 19 '26 12:02

Poyo


1 Answers

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-"
like image 81
cure Avatar answered Feb 21 '26 15:02

cure



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!