提示输入,“此时并未预料到。”

时间:2013-07-17 03:05:24

标签: batch-file

我有一个简单的代码块。之前已经定义了所有变量。它的作用是要求输入1-4,并根据响应检查某些变量是否处于某个水平。如果符合条件,它将根据发生的情况返回一个场景。以下摘录说明了这一点。你选择什么选择并不重要,它似乎总是返回and was unexpected at this time.

set /p choice="By whom do you sit (1-4)? "

if !choice! GTR 4 echo Please enter a valid number. && goto thehogwartsexpress
if !choice! LSS 1 echo Please enter a valid number. && goto thehogwartsexpress
if "!choice!" EQU "1" (
    echo It was an interesting ride. You find out their names are Fred and George Weasley, second-years who enjoy gags and jokes. You tell them your name is !char_name!.
    if !char_ilvl! GTR 1 ( 
        echo You think they're slackers, but then again, they seem friendly.
        if !char_clvl! GTR 1 echo You talk to them occasionally throughout the ride. You've entered their frame of trust. You buy scrumptious delights from the witch's carriage. Character + 1. && set /a char_char=char_char+1
        if !char_clvl! EQU 0 echo You smirk at a few of their jokes and talk once or twice, but no more.
        echo [press enter]
        pause>nul
        goto hogwartsschoolarrival
    ) else (
        if !char_clvl! GTR 1 echo You all jester around and get to know each other. Looks like you've made two new friends for life. Character + 1. && set /a char_char=char_char+1
        if !char_clvl! EQU 0 echo You laugh a bit at their jokes and try to talk a bit. They think you're cool. Character + 1. && set /a char_char=char_char+1
        echo [press enter]
        pause>nul
        goto hogwartsschoolarrival
    )
) else if "!choice!" EQU "2" (
    if "!char_gen!" EQU "male" (
        if !char_rlvl! GTR 1 echo You introduce yourself as !char_name!, unveiling that their names are Angelina Johnson (black female) and Katie Bell (brunette). You easily become friends with the two. Charisma + 1. && set /a char_risma=char_risma+1
        if !char_rlvl! LSS 2 echo You sort of talked to them. Nice attempt. They like you, but they don't like you enough. Keep trying.
        echo [press enter]
        pause>nul
        goto hogwartsschoolarrival
    ) else (
        if !char_clvl! GTR 1 echo You introduce yourself as !char_name!, unveiling that their names are Angelina Johnson (black female) and Katie Bell (brunette). You talk to them intently throughout the ride. They talk about Hogwarts and show you a bit of the ropes. Character + 1. && set /a char_char=char_char+1
        if !char_clvl! LSS 2 echo You smiled at each other once or twice, but no more.
        echo [press enter]
        pause>nul
        goto hogwartsschoolarrival
    )
) else if "!choice!" EQU "3" (
    if !char_ilvl! LSS 2 (
        if !char_rlvl! GTR 2 echo You tried to talk to him, but to no avail. He simply glared at you, made a soft gag reflex and stared back out the window solemnly.
        if !char_rlvl! LSS 3 echo You talked not once.
        echo [press enter]
        pause>nul
        goto hogwartsschoolarrival
    ) else (
        echo You sit opposite to him, not saying a word. You plan to keep to yourself, pulling out your edition of "Magical Drafts and Potions," reading page 327. After seven minutes, you notice out of peripheral vision that he looked at you intently. You ignored him. "And what would your name be?" he said in a low, monotonous voice. "!char_name!," you say in the monotonous voice of your own. "Well, you appear to be of some hope for the new students. My name is Severus Snape, your potions teacher," he began with a sharpness in his voice. "I expect to see you in class. Don't disappoint me." With that, you both returned to your own heads. Congratulations, you managed to make friends with one of the most feared teachers in the school. Do well in his class. 
        echo [press enter]
        pause>nul
        goto hogwartsschoolarrival
    )
) else if "!choice!" EQU "4" ( 
    echo You wonder what Hogwarts will be like. 
    echo [press enter]
    pause>nul
    goto hogwartsschoolarrival
)

2 个答案:

答案 0 :(得分:2)

问题不在set,而echoif结合使用。 在这一行:

if "!char_gen!" EQU "male" (
    if !char_rlvl! GTR 1 echo You introduce yourself as !char_name!, unveiling that their names are Angelina Johnson (black female) and Katie Bell (brunette)....

"女性"之间的结束)和"和"打破if

你必须用^:... female ^) and ...

来逃避它

答案 1 :(得分:1)

好的,除非我有大约30分钟的时间来查看整个代码,否则我无法彻底解决这个问题,但我能做的是建议您尝试使用choice命令set /p,因为您只需要一个与您的答案相符的单个数字答案。

替换:

set /p choice="By whom do you sit (1-4)? "

使用:

choice /c 1234 /m "By whom do you sit ?"
set choice=%errorlevel%

你甚至不必改变代码的其余部分! 当然,这是假设错误与问题所指定的输入有关,并且您在计算机上安装了choice.exe。

最后,我建议您通过set /a将选项设置为数字变量,因为它似乎将保留整个程序的数字,并且在良好实践中将其视为一个,但当然我不知道整个剧本,所以我会把它留给你。

你的,莫娜