0

我有一个简单的代码块。所有变量之前都已定义。它所做的是要求输入 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
)
4

2 回答 2

2

你的问题不是 withset而是 withecho结合 with if。在这一行:

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

于 2013-07-21T05:43:19.923 回答
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因为它似乎会在整个程序中保持一个数字,并且将其视为一个数字是一种很好的做法,但是我当然不知道整个脚本,所以我会离开那给你。

你的,莫娜

于 2013-07-17T04:11:23.313 回答