且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

错误:1在这个时候意外

更新时间:2022-10-19 11:40:54

/ P> / code>表示变量是简单地通过用户输入设置。 -

SET

 :winestart
CLS
呼应你都不在话下。你有一瓶葡萄酒,你穿的衣服。
回声你有什么样的酒?
回声。
回声1.红葡萄酒
回声2.白葡萄酒
集/ p input7 =输入:如果%input7%EQU 1页转到redwine
如果%input7%EQU页转到whitewine

由于 input7 未输入,则如果语句间preTED为

 如果EQU页转到redwine

CMD 期望如果事情EQU anotherthing的DoSomething 所以看到 1 作为比较运营商。这是不是承认的运营商之一,所以响应的 1 是意想不到的。

这方面的一个更好的形式是

 如果/我%input7%EQU1转到redwine

其中 / I 强制不区分大小写的比较和引用的论据$ P $用户在其中输入的没有pserves的语法要求>或包含空格的字符串(你必须对用户的响应无法控制的。)

So I'm making a game based on making decisions using notepad ++ and batch. I'm new to this and I have no idea what the problem is here.

:start 
;startup
cls
echo Wine or Cheese?
echo.
echo 1. Wine
echo 2. Cheese
echo 3. Exit
echo.
set /p input0=Enter: 
if %input0% equ 1 goto winestart
if %input0% equ 2 goto cheese
if %input0% equ 3 goto exit

When I select winestart or 1, it goes to winestart for a splitsecond then crashes, with the error message: 1 was unexpected at this time. Winestart looks like this:

:winestart
cls
echo You are alone. You have a bottle of wine and the clothes you are wearing.
echo What kind of wine do you have?
echo.
echo 1. Red Wine
echo 2. White Wine
set p/ input7=Enter:

if %input7% equ 1 goto redwine
if %input7% equ 2 goto whitewine

/p indicates that the variable is simply set by user input. –

SET

:winestart
cls
echo You are alone. You have a bottle of wine and the clothes you are wearing.
echo What kind of wine do you have?
echo.
echo 1. Red Wine
echo 2. White Wine
set /p input7=Enter:

if %input7% equ 1 goto redwine
if %input7% equ 2 goto whitewine

[Edit: Correct cure, but no explanation of why the error message appears]

Since input7 is not entered, the if statement is interpreted as

if equ 1 goto redwine

cmd expects if something equ anotherthing dosomething so it sees 1 as the comparison-operator. This is not one of the operators it recognises, so it responds that the 1 is unexpected.

A better form of this is

if /i "%input7%" equ "1" goto redwine

where the /i forces a case-insensitive comparison and "quoting the arguments" preserves the syntax requirement where the user enters nothing or a string containing spaces (you have no control over the user's response.)