批处理-动态标签或功能 [英] batch - dynamic labels or functions

查看:125
本文介绍了批处理-动态标签或功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在进行批处理文本冒险(因为这是最简单的语言,几乎不需要任何编码经验),并且我想知道是否有办法制作动态的goto或标签.

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.

例如,我有一个动态的健康和能源系统,它显示不同的健康条,具体取决于从C:/驱动器上的保存文件获取的健康变量.

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.

或者,我想有一个动态的goto.我的意思是说一个变量,然后是一个goto函数.

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%

不幸的是,这不起作用,因为goto命令无法识别变量.有没有办法解决这个问题?

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

推荐答案

是的,可以在set命令中删除引号,或在标签中放置引号.

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

set currentlbl=foo-
:foo-

set currentlbl="foo-"
:"foo-"

这篇关于批处理-动态标签或功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆