我的CMD批处理脚本不起作用(此时0意外。)

正如标题所说,我的批处理脚本不工作,所有我知道这个错误发生在“ REM BUCKS ”之后,我也看到文本“ 0在这个时候是意外的在退出之前,你们可以看看有什么问题?也许提供一个解决scheme?我需要这个代码为我的游戏。

这个脚本是一个评分脚本,我通过添加“ SETs

在“ REM分数 ”下,如果收入variables是负值,则将收入设置为0。

我不能给你完整的脚本,因为它是如此之大

这里是代码:

SETLOCAL set stage=add set r=10 set dif=3 set timer=30 set w=2 set cash=6 REM BUCKS if %stage%==cha ( set st=10 REM SCORE call :calculator %r%*10*%dif%*%st%-%w%*%timer% timeout 5 > NUL set earn=%val% if %earn% LSS 0 set earn=0 set /a cash=%cash% + %val% goto :EOF ) if %stage%==0 goto :EOF if %stage%==add set st=3 if %stage%==sub set st=4 if %stage%==mul set st=5 call :calculator %r%*10*%dif%*%st%-(%timer%*%w%) set earn=%val% if %earn% LSS 0 ( set earn=0 ) set /a cash=%cash% + %val% pause exit goto :EOF :calculator >"%temp%\VBS.vbs" echo Set fso = CreateObject("Scripting.FileSystemObject") : Wscript.echo (%*) for /f "delims=" %%a in ('cscript /nologo "%temp%\VBS.vbs"') do set "val=%%a" del "%temp%\VBS.vbs" goto :EOF 

thx阅读

你需要在IF块中延迟扩展 ,我不确定你的vbscript是否不会按照你的意图去做。 这是您的脚本的改进版本,使用uber-geeky批处理/ vbscript混合技术 ,这将减少您的IO操作,脚本将更快:

 @echo off SETLOCAL enableDelayedExpansion set stage=add set r=10 set dif=3 set timer=30 set w=2 set cash=6 REM BUCKS if %stage%==cha ( set st=10 REM SCORE call :calculator "%r%*10*%dif%*%st%-%w%*%timer%" timeout 5 > NUL set earn=!val! if !earn! LSS 0 set earn=0 set /a cash=!cash! + !val! goto :EOF ) if %stage%==0 goto :EOF if %stage%==add set st=3 if %stage%==sub set st=4 if %stage%==mul set st=5 call :calculator "%r%*10*%dif%*%st%-(%timer%*%w%)" set earn=%val% if %earn% LSS 0 ( set earn=0 ) set /a cash=%cash% + %val% echo %cash% for /f "tokens=2" %%# in ("%cmdcmdline%") do if /i "%%#" equ "/c" pause exit /b %errorlevel% :calculator for /f "delims=" %%a in ('cscript /noLogo "%~f0?.WSF" //job:calc "%~1"') do set "val=%%a" exit /b %errorlevel% <job id="calc"> <script language="VBScript"> WScript.Echo(WScript.Arguments.Item(0)) </script> </job>