【问题标题】:IF Block crashing?IF块崩溃?
【发布时间】:2016-03-17 14:12:37
【问题描述】:

我为我的无能深表歉意,因为我刚刚开始使用批处理,但是这个 IF 块每次运行时都会导致我的程序出现语法不正确的错误。我找不到错误,谁能帮忙?

echo What is the scale of this conflict? (Determines length of game) 
echo 1. Small (Quick)
echo 2. Medium (Normal)
echo 3. Large (Extended)
SET /P difficulty="Type 1, 2, or 3, then press ENTER:"
IF %DIFF% == 3 (
set /a troops = %random% %%52 +45
set cities = 10
)
IF %DIFF% == 2 (
set /a troops = %random% %%32 +25
set cities = 6
)
IF %DIFF% == 1 (
set /a troops = %random% %%17 +10
set cities = 3
)

【问题讨论】:

    标签: batch-file if-statement cmd syntax-error batch-processing


    【解决方案1】:

    没有DIFF 变量。可能你需要这个:

    echo What is the scale of this conflict? (Determines length of game) 
    echo 1. Small (Quick)
    echo 2. Medium (Normal)
    echo 3. Large (Extended)
    SET /P difficulty="Type 1, 2, or 3, then press ENTER:"
    IF %difficulty% == 3 (
    set /a troops = %random% %%52 +45
    set cities = 10
    )
    IF %difficulty% == 2 (
    set /a troops = %random% %%32 +25
    set cities = 6
    )
    IF %difficulty% == 1 (
    set /a troops = %random% %%17 +10
    set cities = 3
    )
    

    【讨论】:

    • 这成功了!谢谢,我觉得我忽略了这样简单的事情:)
    猜你喜欢
    • 2016-02-25
    • 2015-10-04
    • 2014-08-12
    • 2018-12-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多