1

When the following piece of code is run in my Batch game for a fight, no matter what the input is it will always attack and go to FIGHTPROCESSORLOOP, and will tell me "Unbalanced parenthesis", while logically with an IF statement nothing should happen when the input isn't the one required, right? The "Travelling" and "Menu" codes work perfectly, so why isn't the "Fight" one working just as well?

:CHOICEPROCESSOR
set /P choice=^>
if /i "%type%"=="travel" (
    if /i "%choice%"=="%choice1%" goto %TRAVELLINGPROCESSOR%
    if /i "%choice%"=="%choice2%" goto %TRAVELLINGPROCESSOR%
    if /i "%choice%"=="%choice3%" goto %TRAVELLINGPROCESSOR%
    if /i "%choice%"=="%choice4%" goto %TRAVELLINGPROCESSOR%
    if /i "%choice%"=="%choice5%" goto %TRAVELLINGPROCESSOR%
)
if /i "%type%"=="menu" (
    if /i "%choice%"=="%choice1%" goto %exec1%
    if /i "%choice%"=="%choice2%" goto %exec2%
    if /i "%choice%"=="%choice3%" goto %exec3%
    if /i "%choice%"=="%choice4%" goto %exec4%
    if /i "%choice%"=="%choice5%" goto %exec5%
)
if /i "%type%"=="fight" (
    if /i "%choice%"=="%weapon%" (
        set /a rsdmg=!ehp!-!atk!
        set /a rsedmg=!hp!-(!eatk!/!def!)
        set /a ehp=!ehp!-!atk!
        set /a hp=!hp!-(!eatk!/!def!)
        if hp GTR bhp set hp=%bhp%
        goto FIGHTPROCESSORLOOP
    )
)
echo Huh?
echo.
goto CHOICEPROCESSOR
3

1 Answer 1

1

Thanks a lot for your help, DavidPostill. Here's what I was doing wrong :

Instead of trying different words, I'd just check the IF statement by leaving my "Choice" empty, meaning I'd just get the original value each time. Nothing wrong with that, then.

As for the math, I'm not sure how I managed to do it, but simply referring to Rob Van der Woude's pages on the matter helped me rewrite a properly functioning code. Instead of using all those variables I've just deleted it all and went for a much simpler approach :

if /i "%type%"=="fight" (
    if /i "%choice%"=="%weapon%" (
        set /a ehp = ehp - atk
        set /a hp = hp - eatk
        goto FIGHTPROCESSORLOOP
    )
)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .