Leveling System is broken and IDK why

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
CodingBear
Posts: 19
Joined: 26 Dec 2014 16:37

Leveling System is broken and IDK why

#1 Post by CodingBear » 20 Apr 2015 18:43

So my problem is that when I go through battle once everything works but when I try to do it again instead of going to battle it just goes to a level up screen. I have looked at the code for 30 mins or so and I can't find why the bug exists

Code: Select all

@echo off
title Levels
color 0a

::Variables
set Playerhealth=100
set Playerdamage=10
set Monsterhealth=50
set Monsterdamage=5
set gold=0
set exp=0
set level=1
set explimit=10

:Intro
echo Welcome to Levels. This is game basically takes place in a large tower with as  many levels as I can make until I get bored. LOOSELY BASED OFF OF SAO :D.
pause
goto Menu

:Menu
cls
echo Welcome to Levels... again.
echo.
echo 1)Start
echo 2)Info
echo 3)Exit
echo.
set /p menu=">>"
if %menu% == 1 goto Level0
if %menu% == 2 goto Info
if %menu% == 3 exit

:Info
cls
echo Most of this game was made while watching PewDiePies Outlast series. Hee have a Cat for reading this =^_^=.... turns out carrots don't show in batch so have this instead :D
pause
goto Menu

:Level0
cls
echo Welcome to Level 0, this area is safe and you can gear up and stuff before      leaving.
echo Level-%level% Exp-%exp%/%explimit%
echo.
echo 1)Go up
echo 2)Shop
echo 3)Advice
echo 4)Exit
echo.
set /p level0=">>"
if %level0% == 1 goto Level1
if %level0% == 2 goto Shop
if %level0% == 3 goto Advice
if %level0% == 4 exit

:Shop
cls
echo Gold %gold%
echo Shop coming soon!
pause
goto Level0

:Advice
cls
echo Did you know the levels get harder as you go? (Thats what she said)
echo.
echo Yes I spent time coding this just to get a thats what she said joke in the game :D
pause
goto Level0

:Level1
cls
echo So this is level 1. It's pretty easy all the monsters are weak. So the way levels work are that each one has a couple of monsters and occasionally there might  be a boss. Defeat them all to advance and collect loot (usually Gold).
pause
cls
echo On your Journey you have encountered a goblin!
pause
goto Level1battle
:Level1battle
if %Playerhealth% LEQ 0 goto Fail
if %Monsterhealth% LEQ 0 goto Victory
cls
echo Player %Playerhealth% Goblin %Monsterhealth%
echo.
echo 1)Attack
echo 2)Run
set /p level1=">>"
if %level1% == 1 goto playerattack
if %level1% == 2 goto Level0

:playerattack
set /a Monsterhealth=%Monsterhealth%-%Playerdamage%
goto monsterattack

:monsterattack
set /a Playerhealth=%Playerhealth%-%Monsterdamage%
goto Level1battle

:Victory
cls
set %Playerhealth%=100
set %Monsterhealth%=50
echo Congratz you beat the monster!
echo You found 50 gold!
echo You gained 5 Exp!
set /a gold=%gold%+50
set /a exp=%exp%+5
if %exp% == %explimit% goto levelup
pause
goto Level0

:levelup
cls
echo Hey you level up congratz!
set /a level=%level%+1
echo You are now Level %level%
set /a explimit=%explimit%+10
echo To level up again you need %explimit% Exp!
echo Your Damage has increased by 5!
set /a Playerdamage=%Playerdamage%+5
pause
goto Level0

:Fail
cls
echo You failed!
set %Playerhealth%=100
set %Monsterhealth%=50
pause
goto Level0

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Leveling System is broken and IDK why

#2 Post by foxidrive » 21 Apr 2015 00:26

The usual culprit is that variables are being reused and not initialised.

I didn't check though - too lazy today. The 20 year old whisky is going down well.

ShadowThief
Expert
Posts: 1167
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: Leveling System is broken and IDK why

#3 Post by ShadowThief » 21 Apr 2015 07:49

foxidrive is right.

At the end of the battle, you never reset the player health or monster health.

Code: Select all

:Victory
cls
set %Playerhealth%=100
set %Monsterhealth%=50


should be

Code: Select all

:Victory
cls
set Playerhealth=100
set Monsterhealth=50


Same thing goes for the :fail code

CodingBear
Posts: 19
Joined: 26 Dec 2014 16:37

Re: Leveling System is broken and IDK why

#4 Post by CodingBear » 21 Apr 2015 12:19

Oh thanks I never caught that. I don't remember adding those

Post Reply