批量游戏地图生成器

时间:2013-09-11 19:14:07

标签: batch-file

它说“此时设置意外”代码:

@echo off
set x=5
set y=5
for /l %%x in (0,1,9) do (
    for /l %%y in (0,1,9) do (
        set /a map=%random% %% 5+1
        if %map% == 5 set m%%x%%y=#
        if not %map% == 5 set m%%x%%y=.
    )
)

问题在于:

set /a map=%random% %% 5+1
if %map% == 5 set m%%x%%y=#
if not %map% == 5 set m%%x%%y=.

1 个答案:

答案 0 :(得分:2)

您需要延迟扩展:

        @echo off
        set x=5
        set y=5
    setlocal enableDelayedExpansion
        for /l %%x in (0,1,9) do (
            for /l %%y in (0,1,9) do (
                set /a map=!random! %% 5+1
                if !map! == 5 set m%%x%%y=#
                if not !map! == 5 set m%%x%%y=.
            )
        )
some other code here
    endlocal

此处有更多信息:http://ss64.com/nt/delayedexpansion.html