help using multiple IF statments.
Moderator: DosItHelp
-
- Posts: 3
- Joined: 19 Aug 2015 19:02
help using multiple IF statments.
im not sure why but i seem to have a problem when the DOS Rpg im making gets to this chunk of code the terminal simply shuts down leaving no time for output. ive tried pausing the terminal in specific areas to see the problem but i cannot seem to find it. hoping i can get some help.
:LevelGauge
if %CharLevel%==1 (
goto LEVEL2
) else if %CharLevel%==2 (
goto LEVEL3
) else if %CharLevel%==3 (
goto LEVEL4
) else if %CharLevel%==4 (
goto LEVEL5
) else if %CharLevel%==5 (
goto LEVEL6
) else if %CharLevel%==6 (
goto LEVEL7
) else if %CharLevel%==7 (
goto LEVEL8
) else if %CharLevel%==8 (
goto LEVEL9
) else if %CharLevel%==9 (
goto LEVEL10
) else (
goto MENU
)
goto MENU
:LEVEL2
if %CharExp% GEQ %CharMaxExp% (
set /a CharExp=%CharExp% -%CharMaxExp%
set CharMaxExp=280
set CharLevel=2
set /a CharAttack=(%CharAttack% * 1.5) + 1
goto LEVELUP
)
:LEVEL3
if %CharExp% GEQ %CharMaxExp% (
set /a CharExp=%CharExp% -%CharMaxExp%
set CharMaxExp=784
set CharLevel=3
set /a CharAttack=(%CharAttack% * 1.5) + 1
goto LEVELUP
) else goto MENU
:LEVEL4
if %CharExp% GEQ %CharMaxExp% (
set /a CharExp=%CharExp% -%CharMaxExp%
set CharMaxExp=1960
set CharLevel=4
set /a CharAttack=(%CharAttack% * 1.5) + 1
goto LEVELUP
) else goto MENU
:LEVEL5
if %CharExp% GEQ %CharMaxExp% (
set /a CharExp=%CharExp% -%CharMaxExp%
set CharMaxExp=3488
set CharLevel=5
set /a CharAttack=(%CharAttack% * 1.5) + 1
goto LEVELUP
) else goto MENU
:LEVEL6
if %CharExp% GEQ %CharMaxExp% (
set /a CharExp=%CharExp% -%CharMaxExp%
set CharMaxExp=5366
set CharLevel=6
set /a CharAttack=(%CharAttack% * 1.5) + 1
goto LEVELUP
) else goto MENU
:LEVEL7
if %CharExp% GEQ %CharMaxExp% (
set /a CharExp=%CharExp% -%CharMaxExp%
set CharMaxExp=8972
set CharLevel=7
set /a CharAttack=(%CharAttack% * 1.5) + 1
goto LEVELUP
) else goto MENU
:LEVEL8
if %CharExp% GEQ %CharMaxExp% (
set /a CharExp=%CharExp% -%CharMaxExp%
set CharMaxExp=11087
set CharLevel=8
goto LEVELUP
) else goto MENU
:LEVEL9
if %CharExp% GEQ %CharMaxExp% (
set /a CharExp=%CharExp% -%CharMaxExp%
set CharMaxExp=14763
set CharLevel=9
set /a CharAttack=(%CharAttack% * 1.5) + 1
goto LEVELUP
) else goto MENU
:LEVEL10
if %CharExp% GEQ %CharMaxExp% (
set /a CharExp=%CharExp% -%CharMaxExp%
set CharLevel=10
set /a CharAttack=(%CharAttack% * 1.5) + 1
goto LEVELUP
) else goto MENU
goto MENU
:LEVELUP
cls
echo You Have Leveled Up.
ping localhost 2 >nul
goto MENU
:LevelGauge
if %CharLevel%==1 (
goto LEVEL2
) else if %CharLevel%==2 (
goto LEVEL3
) else if %CharLevel%==3 (
goto LEVEL4
) else if %CharLevel%==4 (
goto LEVEL5
) else if %CharLevel%==5 (
goto LEVEL6
) else if %CharLevel%==6 (
goto LEVEL7
) else if %CharLevel%==7 (
goto LEVEL8
) else if %CharLevel%==8 (
goto LEVEL9
) else if %CharLevel%==9 (
goto LEVEL10
) else (
goto MENU
)
goto MENU
:LEVEL2
if %CharExp% GEQ %CharMaxExp% (
set /a CharExp=%CharExp% -%CharMaxExp%
set CharMaxExp=280
set CharLevel=2
set /a CharAttack=(%CharAttack% * 1.5) + 1
goto LEVELUP
)
:LEVEL3
if %CharExp% GEQ %CharMaxExp% (
set /a CharExp=%CharExp% -%CharMaxExp%
set CharMaxExp=784
set CharLevel=3
set /a CharAttack=(%CharAttack% * 1.5) + 1
goto LEVELUP
) else goto MENU
:LEVEL4
if %CharExp% GEQ %CharMaxExp% (
set /a CharExp=%CharExp% -%CharMaxExp%
set CharMaxExp=1960
set CharLevel=4
set /a CharAttack=(%CharAttack% * 1.5) + 1
goto LEVELUP
) else goto MENU
:LEVEL5
if %CharExp% GEQ %CharMaxExp% (
set /a CharExp=%CharExp% -%CharMaxExp%
set CharMaxExp=3488
set CharLevel=5
set /a CharAttack=(%CharAttack% * 1.5) + 1
goto LEVELUP
) else goto MENU
:LEVEL6
if %CharExp% GEQ %CharMaxExp% (
set /a CharExp=%CharExp% -%CharMaxExp%
set CharMaxExp=5366
set CharLevel=6
set /a CharAttack=(%CharAttack% * 1.5) + 1
goto LEVELUP
) else goto MENU
:LEVEL7
if %CharExp% GEQ %CharMaxExp% (
set /a CharExp=%CharExp% -%CharMaxExp%
set CharMaxExp=8972
set CharLevel=7
set /a CharAttack=(%CharAttack% * 1.5) + 1
goto LEVELUP
) else goto MENU
:LEVEL8
if %CharExp% GEQ %CharMaxExp% (
set /a CharExp=%CharExp% -%CharMaxExp%
set CharMaxExp=11087
set CharLevel=8
goto LEVELUP
) else goto MENU
:LEVEL9
if %CharExp% GEQ %CharMaxExp% (
set /a CharExp=%CharExp% -%CharMaxExp%
set CharMaxExp=14763
set CharLevel=9
set /a CharAttack=(%CharAttack% * 1.5) + 1
goto LEVELUP
) else goto MENU
:LEVEL10
if %CharExp% GEQ %CharMaxExp% (
set /a CharExp=%CharExp% -%CharMaxExp%
set CharLevel=10
set /a CharAttack=(%CharAttack% * 1.5) + 1
goto LEVELUP
) else goto MENU
goto MENU
:LEVELUP
cls
echo You Have Leveled Up.
ping localhost 2 >nul
goto MENU
Last edited by andrewg250 on 21 Aug 2015 19:19, edited 1 time in total.
-
- Expert
- Posts: 1166
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
Re: help using multiple IF statments.
Your very first else is on a separate line from the rest of the if statement, and that's breaking everything. It's also worth noting that you're going to have problems with both math that is only partially inside of parentheses, and non-integer math in general.
Re: help using multiple IF statments.
You do not need any ELSE statements. Just simplify it.
Code: Select all
:LevelGauge
if %CharLevel%==1 goto LEVEL2
if %CharLevel%==2 goto LEVEL3
if %CharLevel%==3 goto LEVEL4
if %CharLevel%==4 goto LEVEL5
if %CharLevel%==5 goto LEVEL6
if %CharLevel%==6 goto LEVEL7
if %CharLevel%==7 goto LEVEL8
if %CharLevel%==8 goto LEVEL9
if %CharLevel%==9 goto LEVEL10
goto MENU
-
- Expert
- Posts: 1166
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
Re: help using multiple IF statments.
Or, even shorter,
Code: Select all
if %CharLevel% lss 10 (
set /a nextLevel=%CharLevel%+1
goto LEVEL%nextLevel%
)
goto MENU
-
- Posts: 3
- Joined: 19 Aug 2015 19:02
Re: help using multiple IF statments.
oh ok thank you. it was so simple i suppose i tend to over complicate things and make extra unnecessary code
-
- Posts: 3
- Joined: 19 Aug 2015 19:02
Re: help using multiple IF statments.
ok well. although that should have worked it seems the game still crashes? could it be due to the functions syntax in :LEVEL(2-10) ?
Re: help using multiple IF statments.
Again you are not using the correct syntax of the IF ELSE statement nor do you even need it. Just take out the ELSE.
-
- Expert
- Posts: 1166
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
Re: help using multiple IF statments.
Run the script from the command prompt instead of clicking it. When I ran your code, I get
because you can't use parentheses to do math inside of other parentheses (without using the ^ escape character to allow it).
+ was unexpected at this time
because you can't use parentheses to do math inside of other parentheses (without using the ^ escape character to allow it).
Re: help using multiple IF statments.
Batch can only do Integer match as well. You cannot use SET /A for decimal math.
Re: help using multiple IF statments.
ShadowThief wrote:Run the script from the command prompt instead of clicking it. When I ran your code, I get+ was unexpected at this time
because you can't use parentheses to do math inside of other parentheses (without using the ^ escape character to allow it).
No just use QUOTES.
-
- Expert
- Posts: 1166
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
Re: help using multiple IF statments.
That works, too. My point is that you can't nest parentheses like how he's doing it.
Re: help using multiple IF statments.
I think this does what your code does. You'll have to verify it.
Code: Select all
:LevelGauge
if %CharLevel% equ 0 goto :MENU
set /a CharLevel+=1
if %CharExp% LSS %CharMaxExp% goto :MENU
set /a CharExp=CharExp - CharMaxExp
if %Charlevel% EQU 2 set CharMaxExp=280
if %Charlevel% EQU 3 set CharMaxExp=784
if %Charlevel% EQU 4 set CharMaxExp=1960
if %Charlevel% EQU 5 set CharMaxExp=3488
if %Charlevel% EQU 6 set CharMaxExp=5366
if %Charlevel% EQU 7 set CharMaxExp=8972
if %Charlevel% EQU 8 set CharMaxExp=11087
if %Charlevel% EQU 9 set CharMaxExp=14763
set /a CharAttack="(CharAttack * 1.5) + 1"
cls
echo You Have Leveled Up.
ping -n 3 "" >nul
goto :MENU