1

as the title says, my batch script is not working, all i know that this error happens after "REM BUCKS", also i saw the text "0 was unexpected at this time." before quitting, can you guys see what is the problem?and maybe provide a solution?i need this code for my game.

This script is a scoring script, i simulate it by adding the "SETs"

Under the "REM SCORE" will set the earn to 0 if the earn variable is a negative.

I cannot give you the full script beacuse its so huge

here is the code:

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 for reading

aschipfl
  • 33,626
  • 12
  • 54
  • 99
Mr. D
  • 45
  • 1
  • 7
  • 2
    Variable expansion. Maybe [this](http://stackoverflow.com/a/30177832/2861476) could help – MC ND Oct 20 '15 at 10:45

1 Answers1

4

You need delayed expansion int the IF block and I'm not sure if your vbscript will not do what you intend. Here's improved version of your script that uses the uber-geeky batch/vbscript hybrid technique which will reduce your IO operations and the script will be faster:

@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>
npocmaka
  • 55,367
  • 18
  • 148
  • 187