此时,后藤出人意料-批处理 [英] Goto was unexpected at this time - batch

查看:83
本文介绍了此时,后藤出人意料-批处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作基于文本的批处理游戏.但是我刚开始写它从未遇到过的问题.

I am trying to make a batch text-based game. But i encountered a problem just starting to write it what I have never encountered before.

:menu
:: the game menu - opens when the game starts
cls
echo This game is still being made -- expermintal
echo Start Screen:
echo [1] View Changes
echo [2] Start Game
echo enter your choice:
set /p startchoice =
if %startchoice%==1 goto changes
if %startchoice%==2 goto startgame

当我输入1或2时,它显示错误此时goto出乎意料",我该如何解决?

When i type in either 1 or 2, it shows the error "goto was unexpected at this time" How do I fix it?

推荐答案

您的startchoice设置不正确.对set /p使用替代语法,在其中提供提示(并删除startchoice和赋值(=)运算符之间的空格)-我认为这实际上是问题的原因,但可以减少批处理文件如果使用set /p <variable>=<Prompt>语法,则以一行为一行).

Your startchoice isn't being set correctly. Use the alternate syntax for set /p where you supply the prompt there (and remove the space between startchoice and the assignment (=) operator - I think it's actually the cause of the problem, but you can reduce your batch file by a line if you use the set /p <variable>=<Prompt> syntax).

我为gotoecho语句添加了两个目标,因此您可以看到已达到它们:

I added two targets for the goto, and echo statements so you could see they were reached:

:menu
:: the game menu - opens when the game starts
cls
echo This game is still being made -- expermintal
echo Start Screen:
echo [1] View Changes
echo [2] Start Game
set /p startchoice=Enter your choice:

if %startchoice%==1 goto changes
if %startchoice%==2 goto startgame
:changes
echo Changes
goto end
:startgame
echo StartGame
:end

这篇关于此时,后藤出人意料-批处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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