如何在 if 语句后批量使用 goto
How to use goto after an if statement in batch
我确定有人问过这个问题,或者很明显,但我似乎找不到答案!我正在批量制作一种闲置的唱首歌游戏,并且一直停留在升级页面上。我的想法是,我希望玩家按回车键赚钱,然后输入 "upg" 进入升级页面。我收到一条错误消息,指出此时无法识别 goto 命令。然后脚本关闭。这是我拥有的:
@echo off
title HackerClicker 1.2.1
color 0a
:start
set /a mon = 0
echo HkrAssociation Hack protocal v. 1.2.1
echo 2015 HkrAssociation. All rights reserved.
echo.
echo press and hold enter in hack routine to auto-hack and gain money
echo.
set /p= "PRESS ANY KEY TO START ROUTINE"
goto routine
:routine
cls
echo Hack Routine v. 1.2.1
echo.
echo Balance: $%mon%
echo.
echo Type "upg" to go to upgrades
echo.
set /p cmd= "C:\users\h@ck3r\hack_routine>"
set /a mon = %mon% + 1
if %cmd%= upg GOTO upgrades
goto routine
:upgrades
echo more here later
set /p=
谢谢!
在batch中,一个等号用于赋值,两个等号用于比较。因此,您需要使用两个等号来查看 %cmd% 是否为 "upg":
if %cmd%==upg GOTO upgrades
我确定有人问过这个问题,或者很明显,但我似乎找不到答案!我正在批量制作一种闲置的唱首歌游戏,并且一直停留在升级页面上。我的想法是,我希望玩家按回车键赚钱,然后输入 "upg" 进入升级页面。我收到一条错误消息,指出此时无法识别 goto 命令。然后脚本关闭。这是我拥有的:
@echo off
title HackerClicker 1.2.1
color 0a
:start
set /a mon = 0
echo HkrAssociation Hack protocal v. 1.2.1
echo 2015 HkrAssociation. All rights reserved.
echo.
echo press and hold enter in hack routine to auto-hack and gain money
echo.
set /p= "PRESS ANY KEY TO START ROUTINE"
goto routine
:routine
cls
echo Hack Routine v. 1.2.1
echo.
echo Balance: $%mon%
echo.
echo Type "upg" to go to upgrades
echo.
set /p cmd= "C:\users\h@ck3r\hack_routine>"
set /a mon = %mon% + 1
if %cmd%= upg GOTO upgrades
goto routine
:upgrades
echo more here later
set /p=
谢谢!
在batch中,一个等号用于赋值,两个等号用于比较。因此,您需要使用两个等号来查看 %cmd% 是否为 "upg":
if %cmd%==upg GOTO upgrades