سؤال

I have written an rpg game. But it alway says :

Unbalanced parenthesis.

This is the code :

@echo off
chcp 65001
::MAX SETTING
::PLS REFER TO FILES\DIALOGUE\.
set diamaxna=6
set diamaxnr=5
set diamaxsa=2

::MAIN SETTING
:SETTING
cls
echo Set HP of your character.
set /p myhp=
echo Set HP of your enemy.
set /p enhp=
if "%myhp%"=="" set myhp=0
if "%enhp%"=="" set enhp=0
echo Choose difficulty. 1 is the easiest and 3 is the most difficult.
choice /c 123 /n /m "[1,2,3]"
if "%ERRORLEVEL%"=="1" set enatk=25
if "%ERRORLEVEL%"=="2" set enatk=50
if "%ERRORLEVEL%"=="3" set enatk=70
if "%ERRORLEVEL%"=="0" goto :EOF
cls

::HP CHECK (EN & MY)
:battle.check
if %enhp% LEQ 0 goto battle.win
if %myhp% LEQ 0 goto battle.lose

::BATTLEVAR
:sp.bool.check
set /a sp_bool=%random% >nul
if %sp_bool% GTR 250 goto sp.bool.check
if %sp_bool% GTR 100 set special=0
if %sp_bool% LEQ 100 set special=1

::ENEMY DIALOGUE GET AND CHECK
:endia.get
set /a encurdia=%random%*%diamaxnr%/32768+1 >nul
set /p enlongcurdia=<"%~dp0Files\Dialogue\NR\%encurdia%.txt"

:dia.check
if "%special%"=="1" (
set /a curdia=%random%*%diamaxsa%/32768+1 >nul
) ELSE (
set /a curdia=%random%*%diamaxna%/32768+1 >nul
)

:dia.get
if "%special%"=="1" (
set /p longcurdia=<"%~dp0Files\Dialogue\SA\%curdia%.txt"
) ELSE (
set /p longcurdia=<"%~dp0Files\Dialogue\NA\%curdia%.txt"
)

:mydam.get
if "%special%"=="1" (
set /a mydam=60+(%random%*120/32768+1) >nul
) ELSE (
set /a mydam=40+(%random%*30/32768+1) >nul
)

:endam.get
set /a endam=%enatk%+(%random%*10/32768+1) >nul

::BATTLE+DIALOGUE
set /a enhp=enhp-mydam
set /a myhp=myhp-endam
echo %longcurdia%%mydam%. Enemy remain HP %enhp%.
echo %enlongcurdia%%endam%. Your remain HP %myhp%.
goto battle.check

::WIN V.S. LOSE
:battle.win
echo You win!
choice /c YN /n /m "Restart?"
if "%errorlevel%"=="1" goto SETTING
if "%errorlevel%"=="2" goto END

:battle.lose
echo You lose!
choice /c YN /n /m "Restart?"
if "%errorlevel%"=="1" goto SETTING
if "%errorlevel%"=="2" goto END

:END
echo Press any button to exit......
pause >nul

I can't solve it. I read this code for many times but I still can't find the problem.
Actually, what does

Unbalanced Parenthesis
mean?

Any help will be appreciated. ^.^

هل كانت مفيدة؟

المحلول

:mydam.get
if "%special%"=="1" (
set /a mydam=60+(%random%*120/32768+1^) 
) ELSE (
set /a mydam=40+(%random%*30/32768+1^) 
)

The caret (^) "escapes" the ), telling CMD that it's a part of the calculation, not of the IF statement.

  • the >nul on your set /a statements is superfluous.

  • try set /a var=%random% %% %maxvalue% + 1 to roll 1..maxvalue

  • why not use

    set "dialogue=%~dp0Files\Dialogue"

    then "%dialogue%...."

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top