错误:1在这个时候意外 [英] Error: 1 was unexpected at this time

查看:94
本文介绍了错误:1在这个时候意外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我在做基于使用记事本+ +和批量决策游戏。我是新来这个,我不知道这个问题是在这里。

 :启动
;启动
CLS
呼应酒或奶酪?
回声。
1.呼应葡萄酒
2.呼应奶酪
呼应3.退出
回声。
集/ p INPUT0 =输入:
如果%INPUT0%EQU 1页转到winestart
如果%INPUT0%EQU页转到奶酪
如果%INPUT0%EQU 3转到退出

当我选择winestart或1,它进入winestart为splitsecond然后崩溃,并显示错误消息:1是意外的在这个时候。
Winestart看起来是这样的:

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


解决方案

/ 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 $用户在其中输入的没有或包含空格的字符串(你必须对用户的响应无法控制的。)

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.)

这篇关于错误:1在这个时候意外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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