IF批量报表不起作用? [英] IF Statement in batch not working?
本文介绍了IF批量报表不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我现在正在批量编写游戏,当我遇到这个问题时,我并没有走得太远。我正在尝试为用户答案设置变量,然后将该答案用于IF语句,但由于某种原因,它总是转到:退出
块。有关如何解决此问题的任何想法?
I'm coding a game in batch right now, and I've not gone very far when I encountered this problem. I'm trying to set a variable for a user answer, then use that answer for an IF statement, but for some reason it always goes to the :Quit
block. Any ideas on how to fix this?
Echo . Are you ready?
Echo Your options are:
call :colorEcho C "================="
Echo.
Echo 1. Yes
Echo 2. No
call :colorEcho C "================="
Echo.
Echo Please enter the number corresponding to your answer.
set /p Answer1 = "Enter your choice: "
if "%Answer1%" == "1" goto Game
if "%Answer1%" == "2" goto Quit
:Quit
Echo You have chosen to quit.
pause
exit
:Game
::Game goes here.
Echo Test
pause
pause
exit
:colorEcho
echo off
<nul set /p ".=%DEL%" > "%~2"
findstr /v /a:%1 /R "^$" "%~2" nul
del "%~2" > nul 2>&1i
colorEcho只为一串文字设置不同的颜色。
colorEcho just sets a different color for a string of text.
当我运行游戏时会发生这种情况:
This is what happens when I run the game:
选择的选项1:
选择选项2:
提前致谢!
黑桃
推荐答案
那是因为%Answer1%
未定义。
set /p Answer1 = "Enter your choice: "
设置一个名为%Answer1%
的变量(注意空格!)
sets a variable named %Answer1 %
(note the space!)
删除 =
周围的空格。
这篇关于IF批量报表不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文