Batch RPG Turn combat

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

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

Re: Batch Command line game

#16 Post by ShadowThief » 10 Oct 2015 13:12

Add

Code: Select all

goto main
at the end of :load

j0y
Posts: 26
Joined: 10 Oct 2015 08:22

Re: Batch Command line game

#17 Post by j0y » 10 Oct 2015 13:23

Shadow Thief, you have helped me and it detects the .bat file now. However, when I try to load it, it says
expmax=150 was not expected at this time
and then closes the command prompt.

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

Re: Batch Command line game

#18 Post by ShadowThief » 10 Oct 2015 13:30

Yes, because you are saving incorrectly.

Your save function looks like this:

Code: Select all

:save
(
echo set level=%level%
echo set health=%health%
echo set money=%money%
echo set exp=%exp%
echo set expmax=%expmax%
echo set str=%str%
echo set def=%def%
echo set wep=%wep%
echo set wepdis=%wepdis%
echo set arm=%arm%
echo set armdis=%armdis%
echo set hpots=%hpots%) >Save.bat


while your load function looks like this:

Code: Select all

:load
if not exist Save.bat goto loaderror
< Save.bat (
set /p name=
set /p level=
set /p health=
set /p money=
set /p exp=
set /p expmax=
set /p str=
set /p def=
set /p wep=
set /p wepdis=
set /p arm=
set /p armdis=
set /p hpots=
set /p spl=
set /p spldis=
)


See how you are loading more things than you are loading? You can't do that. The load function that you're using works by reading in the file one line at a time and storing that line to the variable on the same line that is within the parentheses, so your %name% variable is getting loaded with your saved %level% value, your %level% variable is getting loaded with your saved %health% value, and so forth. Also, the entire line is being stored as a variable, so when you load name, you are essentially using the code

Code: Select all

set /p name=set level=%level%
which will never work and is why you are getting errors. Your save code should look like this:

Code: Select all

:save
(
echo %name%
echo %level%
echo %health%
echo %money%
echo %exp%
echo %expmax%
echo %str%
echo %def%
echo %wep%
echo %wepdis%
echo %arm%
echo %armdis%
echo %hpots%
echo %spl%
echo %spldis%) >Save.bat
goto main
cls
echo Game Saved!
pause >nul
goto main

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Batch Command line game

#19 Post by Squashman » 10 Oct 2015 13:33

j0y wrote:Shadow Thief, you have helped me and it detects the .bat file now. However, when I try to load it, it says
expmax=150 was not expected at this time
and then closes the command prompt.

Because of my previous example telling you that you can NOT use a mix of both sets of code! It will not execute correctly.

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Batch Command line game

#20 Post by Squashman » 10 Oct 2015 13:35

May I suggest not calling the saved game settings SAVE.bat.
I would suggest calling it save.ini or something like that.

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

Re: Batch Command line game

#21 Post by ShadowThief » 10 Oct 2015 13:38

I agree, and will also add that you can make the extension anything you want, as it's just a text file.

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Batch Command line game

#22 Post by Squashman » 10 Oct 2015 13:42

I will also suggest that you document in your batch file where you got all your help from since this is home work and all.

My Mother is a teacher and they have software now that reads a document and determines what percentage of the document may have been plagiarized. I would assume this software also searches the Internet for web published articles as well, probably using search engines like Google and Bing to try and find matches.

Give credit where credit is due.

TheHunterManX
Posts: 54
Joined: 14 Aug 2015 05:59

Re: Batch Command line game

#23 Post by TheHunterManX » 10 Oct 2015 13:45

I have found the problem! the save file did not save all variables (spl and spldis) so when it went to main it had trouble proseccing %spl% so it closed as a result. Use during saving this:

Code: Select all

:save
(
echo set level=%level%
echo set health=%health%
echo set money=%money%
echo set exp=%exp%
echo set expmax=%expmax%
echo set str=%str%
echo set def=%def%
echo set wep=%wep%
echo set wepdis=%wepdis%
echo set arm=%arm%
echo set armdis=%armdis%
echo set hpots=%hpots%
echo set spl=%spl%
echo set spldis=%spldis%)>Save.bat
cls
echo Game Saved!
pause >nul

And this during loading:

Code: Select all

:load
if exist Save.bat (
call Save.bat) else (
goto loaderror)
goto menu
:loaderror
cls
echo there is an error with the save file. Please start a new game to continue...
pause >nul


Also I emphasize you use call instead of goto for most things as it will help immensly,

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Batch Command line game

#24 Post by Squashman » 10 Oct 2015 13:48

TheHunterManX wrote:Also I emphasize you use call instead of goto for most things as it will help immensly,

It is REQUIRED in this instance!

TheHunterManX
Posts: 54
Joined: 14 Aug 2015 05:59

Re: Batch Command line game

#25 Post by TheHunterManX » 10 Oct 2015 13:58

I was talking about using it for calling The label, not the file. Besides, here is the full original code with fix:

Code: Select all

title AWB
color a
@echo off
:menu
color a
cls
echo =========================
echo Arena of the White Bear
echo =========================
echo.
echo 1)Start
echo 2)Load
echo 3)Exit
echo.
set /p input=Enter:

if %input% == 1 goto start
if %input% == 2 goto load
if %input% == 3 exit
goto menu

:start
set level=1
set health=100
set money=50
set exp=0
set expmax=100
set str=10
set def=0
set wep=0
set wepdis=None
set arm=0
set armdis=None
set hpots=2
set spl=0
set spldis=None
cls
echo Your name is Rosanna. You are a slave, but the Jarl of the North's End has
echo offered you a chance to gain freedom, in exchange you make an interesting and
echo gruesome display in the Arena of the White Bear. Go on, it is your chance,
echo and nothing is going to wrench this away from you.

pause >nul

cls

goto main

:main
if %exp% GEQ %expmax% goto levelup
if %money% LSS 0 set money=0
if %wep% == 1 set wepdis=Whip   
if %wep% == 2 set wepdis=Axe
if %wep% == 3 set wepdis=Greatsword
if %wep% == 4 set wepdis=Bow
if %wep% == 5 set wepdis=Flintlock Pistol
if %wep% == 6 set wepdis=Hunter's Rifle
if %wep% == 1 set str=13
if %wep% == 2 set str=16
if %wep% == 3 set str=19
if %wep% == 4 set str=21
if %wep% == 5 set str=25
if %wep% == 6 set str=30
if %arm% == 1 set armdis=Leather
if %arm% == 2 set armdis=Iron
if %arm% == 3 set armdis=Titanium
if %arm% == 4 set armdis=Werewolf Silver
if %arm% == 1 set def=2
if %arm% == 2 set def=3
if %arm% == 3 set def=5
if %arm% == 4 set def=7
if %spl% == 1 set spldis=Fireball
if %spl% == 2 set spldis=Thunder Bolt
if %spl% == 1 set spl=5
if %spl% == 2 set spl=10
cls
echo AWB
echo -----------------------------------------------
echo Rosanna  Level:%level%   Money:$%money%
echo Hp:%health%/100  Xp:%exp%/%expmax%
echo Weapon:%wepdis%  Armour:%armdis% Spell:%spldis%
echo -----------------------------------------------
echo 1)Fight
echo 2)Shop
echo 3)Save
echo 4)Exit
echo.
set /p input=Enter:

if %input% == 1 goto fight1
if %input% == 2 goto shop
if %input% == 3 goto save
if %input% == 4 goto exit
goto main

:load
if not exist Save.bat goto loaderror
< Save.bat (
set /p name=
set /p level=
set /p health=
set /p money=
set /p exp=
set /p expmax=
set /p str=
set /p def=
set /p wep=
set /p wepdis=
set /p arm=
set /p armdis=
set /p hpots=
set /p spl=
set /p spldis=
)

:loaderror
cls
echo No save file found...
pause >nul
goto menu

:fight1
set enhealth=70

:fight
if %health% GTR 100 set health=100
if %health% LSS 1 goto lose
cls
echo FIGHT
echo -------------------------------------------------
echo Rosanna Hp:%health%/100 Level:%level%
echo Weapon:%wepdis%  Armour:%armdis% Spell:%spldis%
echo -------------------------------------------------
echo Enemy
echo Hp:%enhealth%/70
echo.
echo 1) Attack
echo 2) Drink Potion
echo 3) Spell
echo 4) Flee
echo.
set /p input=Enter:

if %input% == 1 goto attack
if %input% == 2 goto potion
if %input% == 3 goto spell
if %input% == 4 goto flee
goto fight

:attack
set num=%random:~-2%
if %num% GTR %str% goto attack
if %num% LSS 0 goto attack
if %num% == 00 set num=0
if %num% == 01 set num=1
if %num% == 02 set num=2
if %num% == 03 set num=3
if %num% == 04 set num=4
if %num% == 05 set num=5
if %num% == 06 set num=6
if %num% == 07 set num=7
if %num% == 08 set num=0
if %num% == 09 set num=7
cls
echo You take %num% health from
echo the enemy.
pause >nul
set /a enhealth= %enhealth% - %num%
set /a exp= %exp% + %num% * 2
goto enattack

:enattack
if %enhealth% LSS 1 goto win
set num=%random:~-1%
if %num% GTR 7 goto enattack
if %num% LSS 0 goto enattack
set /a num= %num% - %def%
if %num% LSS 0 set num=0
cls
echo The enemy takes %num% health
echo from you.
pause >nul
set /a health= %health% - %num%
goto fight

:spell

set num=%spl%
if %num% GTR %str% goto attack
if %num% LSS 0 goto attack
if %num% == 00 set num=0
if %num% == 01 set num=1
if %num% == 02 set num=2
if %num% == 03 set num=3
if %num% == 04 set num=4
if %num% == 05 set num=5
if %num% == 06 set num=6
if %num% == 07 set num=7
if %num% == 08 set num=0
if %num% == 09 set num=7
cls
echo You cast a spell and take %num% health from
echo the enemy.
echo.
pause >nul
set /a enhealth= %enhealth% - %num%
set /a exp= %exp% + %num% * 2
goto enattack

:win
set num=%random:~-2%
if %num% GTR 35 goto win
if %num% LSS 15 goto win
cls
echo Congratulations, you killed
echo the enemy!
echo.
echo You found $%num%
pause >nul
set /a money= %money% + %num%
goto main

:lose
cls
color c
echo Oh no, you died!
echo.
echo You will have to start again! Your save file has been deleted!
del save
pause >nul
goto menu

:potion
cls
echo 1)Drink Potion
echo 2)Back
echo.
set /p input=Enter:

if %input% == 2 goto fight
if %hpots% LSS 1 set goto nopots
if %input% == 1 set health=%health%
if %input% == 1 set /a hpots= %hpots% - 1
if %input% == 1 set /a health= %health% + 35
if %input% == 1 goto fight
goto potion

:nopots
cls
echo You have no potions left!
pause >nul
goto fight

:flee
cls
echo You run away!
echo.
echo -$30
pause >nul
set /a money= %money% - 30
goto main

:shop
cls
echo SHOP
echo --------------------------------------
echo Rosanna
echo Money:$%money% Level:%level%
echo --------------------------------------
echo [a)Weapons]b)Armour]c)Potions]d)Spells
echo.
echo 1) Whip             $30     Lvl: 1
echo 2) Axe              $70     Lvl: 3
echo 3) Greatsword       $150    Lvl: 6
echo 4) Bow              $200    Lvl: 7
echo 5) Flintlock Pistol $250    Lvl: 7
echo 6) Hunter's Rifle   $300    Lvl: 8
echo 7) Back
echo.
set /p input=Enter:

if %input% == 7 goto main
if %input% == a goto shop
if %input% == b goto shop2
if %input% == c goto shop3
if %input% == d goto shop4
if %money% LSS 30 goto nofunds
if %input% == 1 set /a money= %money% - 30
if %input% == 1 set wep=1
if %input% == 1 goto main
if %level% LSS 3 goto nolev
if %money% LSS 70 goto nofunds
if %input% == 2 set /a money= %money% - 70
if %input% == 2 set wep=2
if %input% == 2 goto main
if %level% LSS 6 goto nolev
if %money% LSS 150 goto nofunds
if %input% == 3 set /a money= %money% - 150
if %input% == 3 set wep=3
if %input% == 3 goto main
if %input% == 4 set /a money= %money% - 200
if %input% == 4 set wep=4
if %input% == 4 goto main
if %level% LSS 7 goto nolev
if %money% LSS 200 goto nofunds
if %input% == 5 set /a money= %money% - 250
if %input% == 5 set wep=5
if %input% == 5 goto main
if %level% LSS 7 goto nolev
if %money% LSS 250 goto nofunds
if %input% == 6 set /a money= %money% - 300
if %input% == 6 set wep=6
if %input% == 6 goto main
if %level% LSS 8 goto nolev
if %money% LSS 300 goto nofunds
goto shop

:shop2
cls
echo SHOP
echo --------------------------------------
echo Rosanna
echo Money:$%money% Level:%level%
echo --------------------------------------
echo [a)Weapons]b)Armour]c)Potions]d)Spells
echo.
echo 1) Leather          $50     Lvl: 1
echo 2) Iron             $90     Lvl: 3
echo 3) Titanium         $200    Lvl: 6
echo 4) Werewolf Silver  $275    Lvl: 8
echo 5) Back
echo.
set /p input=Enter:

if %input% == 5 goto main
if %input% == a goto shop
if %input% == b goto shop2
if %input% == c goto shop3
if %input% == d goto shop4
if %money% LSS 50 goto nofunds
if %input% == 1 set /a money= %money% - 50
if %input% == 1 set arm=1
if %input% == 1 goto main
if %level% LSS 3 goto nolev
if %money% LSS 90 goto nofunds
if %input% == 2 set /a money= %money% - 90
if %input% == 2 set arm=2
if %input% == 2 goto main
if %level% LSS 6 goto nolev
if %money% LSS 200 goto nofunds
if %input% == 3 set /a money= %money% - 200
if %input% == 3 set arm=3
if %input% == 3 goto main
if %input% == 4 set /a money= %money% - 275
if %input% == 4 set arm=5
if %input% == 4 goto main
if %level% LSS 8 goto nolev
if %money% LSS 275 goto nofunds
goto shop2

:shop3
cls
echo SHOP
echo --------------------------------------
echo Rosanna
echo Money:$%money% Level:%level%
echo --------------------------------------
echo [a)Weapons[b)Armour[c)Potions]d)Spells
echo.
echo 1)Health Potion    $30
echo 2)Level Potion     $1000
echo 3)Back
echo.
echo.
set /p input=Enter:

if %input% == 3 goto main
if %input% == a goto shop
if %input% == b goto shop2
if %input% == c goto shop3
if %input% == d goto shop4
if %money% LSS 30 goto nofunds
if %input% == 1 set /a money= %money% - 30
if %input% == 1 set hpots= %hpots% + 1
if %input% == 1 goto main
if %money% LSS 1000 goto nofunds
if %input% == 2 set /a money= %money% - 1000
if %input% == 2 goto main
goto shop3

:shop4
cls
echo SHOP
echo --------------------------------------
echo Rosanna
echo Money:$%money% Level:%level%
echo --------------------------------------
echo [a)Weapons[b)Armour[c)Potions]d)Spells
echo.
echo 1) Fireball     $50     Lvl: 1
echo 2) Thunder Bolt $150    Lvl: 2
echo 3) Back
echo.
echo.
set /p input=Enter:
if %input% == 3 goto main
if %input% == a goto shop
if %input% == b goto shop2
if %input% == c goto shop3
if %input% == d goto shop4
if %money% LSS 50 goto nofunds
if %input% == 1 set /a money= %money% - 50
if %input% == 1 set spl=5
if %input% == 1 set spldis=Fireball
if %input% == 1 goto main
if %level% LSS 1 goto nolev
if %money% LSS 150 goto nofunds
if %input% == 2 set /a money= %money% - 150
if %input% == 2 set spl=10
if %input% == 2 set spldis=Thunder Bolt
if %input% == 2 goto main
if %level% LSS 2 goto nolev
goto shop4

:nofunds
cls
echo You don't have enough money
echo to purchase this item.
pause >nul
goto main

:nolev
cls
echo Your level isn't high enough
echo to purchase this item.
pause >nul
goto main

:save
(
echo set level=%level%
echo set health=%health%
echo set money=%money%
echo set exp=%exp%
echo set expmax=%expmax%
echo set str=%str%
echo set def=%def%
echo set wep=%wep%
echo set wepdis=%wepdis%
echo set arm=%arm%
echo set armdis=%armdis%
echo set hpots=%hpots%
echo set spl=%spl%
echo set spldis=%spldis%) >Save.bat
cls
echo Game Saved!
pause >nul
goto main

:exit
cls
echo All unsaved progress will be
echo lost, are you sure? (Y/N)
set /p input=

if %input% == y exit
if %input% == n goto main
goto exit
pause >nul
exit

:levelup
set /a level= %level% + 1
set exp=0
set /a expmax= %expmax% * 150 / 100
cls
echo Congratulations!
echo You are now level %level%!
echo.
pause >nul
goto main

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

Re: Batch Command line game

#26 Post by ShadowThief » 10 Oct 2015 14:12

TheHunterManX wrote:I was talking about using it for calling The label, not the file. Besides, here is the full original code with fix:

You didn't even test this. The save/load function still doesn't work.

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Batch Command line game

#27 Post by Squashman » 10 Oct 2015 14:13

ShadowThief wrote:
TheHunterManX wrote:I was talking about using it for calling The label, not the file. Besides, here is the full original code with fix:

You didn't even test this. The save/load function still doesn't work.

Was just going to point that out.

HunterMan, I already explained that you can't mix and match this type of code logic!!!

Code: Select all

:load
if not exist Save.bat goto loaderror
< Save.bat (
set /p name=
set /p level=
set /p health=
set /p money=
set /p exp=
set /p expmax=
set /p str=
set /p def=
set /p wep=
set /p wepdis=
set /p arm=
set /p armdis=
set /p hpots=
set /p spl=
set /p spldis=
)


Code: Select all

:save
(
echo set level=%level%
echo set health=%health%
echo set money=%money%
echo set exp=%exp%
echo set expmax=%expmax%
echo set str=%str%
echo set def=%def%
echo set wep=%wep%
echo set wepdis=%wepdis%
echo set arm=%arm%
echo set armdis=%armdis%
echo set hpots=%hpots%
echo set spl=%spl%
echo set spldis=%spldis%) >Save.bat

TheHunterManX
Posts: 54
Joined: 14 Aug 2015 05:59

Re: Batch Command line game

#28 Post by TheHunterManX » 10 Oct 2015 14:29

Yes, i see, so here is the fixed version:

Code: Select all

title AWB
color a
@echo off
:menu
color a
cls
echo =========================
echo Arena of the White Bear
echo =========================
echo.
echo 1)Start
echo 2)Load
echo 3)Exit
echo.
set /p input=Enter:

if %input% == 1 goto start
if %input% == 2 goto load
if %input% == 3 exit
goto menu

:start
set level=1
set health=100
set money=50
set exp=0
set expmax=100
set str=10
set def=0
set wep=0
set wepdis=None
set arm=0
set armdis=None
set hpots=2
set spl=0
set spldis=None
cls
echo Your name is Rosanna. You are a slave, but the Jarl of the North's End has
echo offered you a chance to gain freedom, in exchange you make an interesting and
echo gruesome display in the Arena of the White Bear. Go on, it is your chance,
echo and nothing is going to wrench this away from you.

pause >nul

cls

goto main

:main
if %exp% GEQ %expmax% goto levelup
if %money% LSS 0 set money=0
if %wep% == 1 set wepdis=Whip   
if %wep% == 2 set wepdis=Axe
if %wep% == 3 set wepdis=Greatsword
if %wep% == 4 set wepdis=Bow
if %wep% == 5 set wepdis=Flintlock Pistol
if %wep% == 6 set wepdis=Hunter's Rifle
if %wep% == 1 set str=13
if %wep% == 2 set str=16
if %wep% == 3 set str=19
if %wep% == 4 set str=21
if %wep% == 5 set str=25
if %wep% == 6 set str=30
if %arm% == 1 set armdis=Leather
if %arm% == 2 set armdis=Iron
if %arm% == 3 set armdis=Titanium
if %arm% == 4 set armdis=Werewolf Silver
if %arm% == 1 set def=2
if %arm% == 2 set def=3
if %arm% == 3 set def=5
if %arm% == 4 set def=7
if %spl% == 1 set spldis=Fireball
if %spl% == 2 set spldis=Thunder Bolt
if %spl% == 1 set spl=5
if %spl% == 2 set spl=10
cls
echo AWB
echo -----------------------------------------------
echo Rosanna  Level:%level%   Money:$%money%
echo Hp:%health%/100  Xp:%exp%/%expmax%
echo Weapon:%wepdis%  Armour:%armdis% Spell:%spldis%
echo -----------------------------------------------
echo 1)Fight
echo 2)Shop
echo 3)Save
echo 4)Exit
echo.
set /p input=Enter:

if %input% == 1 goto fight1
if %input% == 2 goto shop
if %input% == 3 goto save
if %input% == 4 goto exit
goto main

:load
if not exist Save.bat goto loaderror
call Save.bat
goto main
:loaderror
cls
echo No save file found...
pause >nul
goto menu

:fight1
set enhealth=70

:fight
if %health% GTR 100 set health=100
if %health% LSS 1 goto lose
cls
echo FIGHT
echo -------------------------------------------------
echo Rosanna Hp:%health%/100 Level:%level%
echo Weapon:%wepdis%  Armour:%armdis% Spell:%spldis%
echo -------------------------------------------------
echo Enemy
echo Hp:%enhealth%/70
echo.
echo 1) Attack
echo 2) Drink Potion
echo 3) Spell
echo 4) Flee
echo.
set /p input=Enter:

if %input% == 1 goto attack
if %input% == 2 goto potion
if %input% == 3 goto spell
if %input% == 4 goto flee
goto fight

:attack
set num=%random:~-2%
if %num% GTR %str% goto attack
if %num% LSS 0 goto attack
if %num% == 00 set num=0
if %num% == 01 set num=1
if %num% == 02 set num=2
if %num% == 03 set num=3
if %num% == 04 set num=4
if %num% == 05 set num=5
if %num% == 06 set num=6
if %num% == 07 set num=7
if %num% == 08 set num=0
if %num% == 09 set num=7
cls
echo You take %num% health from
echo the enemy.
pause >nul
set /a enhealth= %enhealth% - %num%
set /a exp= %exp% + %num% * 2
goto enattack

:enattack
if %enhealth% LSS 1 goto win
set num=%random:~-1%
if %num% GTR 7 goto enattack
if %num% LSS 0 goto enattack
set /a num= %num% - %def%
if %num% LSS 0 set num=0
cls
echo The enemy takes %num% health
echo from you.
pause >nul
set /a health= %health% - %num%
goto fight

:spell

set num=%spl%
if %num% GTR %str% goto attack
if %num% LSS 0 goto attack
if %num% == 00 set num=0
if %num% == 01 set num=1
if %num% == 02 set num=2
if %num% == 03 set num=3
if %num% == 04 set num=4
if %num% == 05 set num=5
if %num% == 06 set num=6
if %num% == 07 set num=7
if %num% == 08 set num=0
if %num% == 09 set num=7
cls
echo You cast a spell and take %num% health from
echo the enemy.
echo.
pause >nul
set /a enhealth= %enhealth% - %num%
set /a exp= %exp% + %num% * 2
goto enattack

:win
set num=%random:~-2%
if %num% GTR 35 goto win
if %num% LSS 15 goto win
cls
echo Congratulations, you killed
echo the enemy!
echo.
echo You found $%num%
pause >nul
set /a money= %money% + %num%
goto main

:lose
cls
color c
echo Oh no, you died!
echo.
echo You will have to start again! Your save file has been deleted!
del save
pause >nul
goto menu

:potion
cls
echo 1)Drink Potion
echo 2)Back
echo.
set /p input=Enter:

if %input% == 2 goto fight
if %hpots% LSS 1 set goto nopots
if %input% == 1 set health=%health%
if %input% == 1 set /a hpots= %hpots% - 1
if %input% == 1 set /a health= %health% + 35
if %input% == 1 goto fight
goto potion

:nopots
cls
echo You have no potions left!
pause >nul
goto fight

:flee
cls
echo You run away!
echo.
echo -$30
pause >nul
set /a money= %money% - 30
goto main

:shop
cls
echo SHOP
echo --------------------------------------
echo Rosanna
echo Money:$%money% Level:%level%
echo --------------------------------------
echo [a)Weapons]b)Armour]c)Potions]d)Spells
echo.
echo 1) Whip             $30     Lvl: 1
echo 2) Axe              $70     Lvl: 3
echo 3) Greatsword       $150    Lvl: 6
echo 4) Bow              $200    Lvl: 7
echo 5) Flintlock Pistol $250    Lvl: 7
echo 6) Hunter's Rifle   $300    Lvl: 8
echo 7) Back
echo.
set /p input=Enter:

if %input% == 7 goto main
if %input% == a goto shop
if %input% == b goto shop2
if %input% == c goto shop3
if %input% == d goto shop4
if %money% LSS 30 goto nofunds
if %input% == 1 set /a money= %money% - 30
if %input% == 1 set wep=1
if %input% == 1 goto main
if %level% LSS 3 goto nolev
if %money% LSS 70 goto nofunds
if %input% == 2 set /a money= %money% - 70
if %input% == 2 set wep=2
if %input% == 2 goto main
if %level% LSS 6 goto nolev
if %money% LSS 150 goto nofunds
if %input% == 3 set /a money= %money% - 150
if %input% == 3 set wep=3
if %input% == 3 goto main
if %input% == 4 set /a money= %money% - 200
if %input% == 4 set wep=4
if %input% == 4 goto main
if %level% LSS 7 goto nolev
if %money% LSS 200 goto nofunds
if %input% == 5 set /a money= %money% - 250
if %input% == 5 set wep=5
if %input% == 5 goto main
if %level% LSS 7 goto nolev
if %money% LSS 250 goto nofunds
if %input% == 6 set /a money= %money% - 300
if %input% == 6 set wep=6
if %input% == 6 goto main
if %level% LSS 8 goto nolev
if %money% LSS 300 goto nofunds
goto shop

:shop2
cls
echo SHOP
echo --------------------------------------
echo Rosanna
echo Money:$%money% Level:%level%
echo --------------------------------------
echo [a)Weapons]b)Armour]c)Potions]d)Spells
echo.
echo 1) Leather          $50     Lvl: 1
echo 2) Iron             $90     Lvl: 3
echo 3) Titanium         $200    Lvl: 6
echo 4) Werewolf Silver  $275    Lvl: 8
echo 5) Back
echo.
set /p input=Enter:

if %input% == 5 goto main
if %input% == a goto shop
if %input% == b goto shop2
if %input% == c goto shop3
if %input% == d goto shop4
if %money% LSS 50 goto nofunds
if %input% == 1 set /a money= %money% - 50
if %input% == 1 set arm=1
if %input% == 1 goto main
if %level% LSS 3 goto nolev
if %money% LSS 90 goto nofunds
if %input% == 2 set /a money= %money% - 90
if %input% == 2 set arm=2
if %input% == 2 goto main
if %level% LSS 6 goto nolev
if %money% LSS 200 goto nofunds
if %input% == 3 set /a money= %money% - 200
if %input% == 3 set arm=3
if %input% == 3 goto main
if %input% == 4 set /a money= %money% - 275
if %input% == 4 set arm=5
if %input% == 4 goto main
if %level% LSS 8 goto nolev
if %money% LSS 275 goto nofunds
goto shop2

:shop3
cls
echo SHOP
echo --------------------------------------
echo Rosanna
echo Money:$%money% Level:%level%
echo --------------------------------------
echo [a)Weapons[b)Armour[c)Potions]d)Spells
echo.
echo 1)Health Potion    $30
echo 2)Level Potion     $1000
echo 3)Back
echo.
echo.
set /p input=Enter:

if %input% == 3 goto main
if %input% == a goto shop
if %input% == b goto shop2
if %input% == c goto shop3
if %input% == d goto shop4
if %money% LSS 30 goto nofunds
if %input% == 1 set /a money= %money% - 30
if %input% == 1 set hpots= %hpots% + 1
if %input% == 1 goto main
if %money% LSS 1000 goto nofunds
if %input% == 2 set /a money= %money% - 1000
if %input% == 2 goto main
goto shop3

:shop4
cls
echo SHOP
echo --------------------------------------
echo Rosanna
echo Money:$%money% Level:%level%
echo --------------------------------------
echo [a)Weapons[b)Armour[c)Potions]d)Spells
echo.
echo 1) Fireball     $50     Lvl: 1
echo 2) Thunder Bolt $150    Lvl: 2
echo 3) Back
echo.
echo.
set /p input=Enter:
if %input% == 3 goto main
if %input% == a goto shop
if %input% == b goto shop2
if %input% == c goto shop3
if %input% == d goto shop4
if %money% LSS 50 goto nofunds
if %input% == 1 set /a money= %money% - 50
if %input% == 1 set spl=5
if %input% == 1 set spldis=Fireball
if %input% == 1 goto main
if %level% LSS 1 goto nolev
if %money% LSS 150 goto nofunds
if %input% == 2 set /a money= %money% - 150
if %input% == 2 set spl=10
if %input% == 2 set spldis=Thunder Bolt
if %input% == 2 goto main
if %level% LSS 2 goto nolev
goto shop4

:nofunds
cls
echo You don't have enough money
echo to purchase this item.
pause >nul
goto main

:nolev
cls
echo Your level isn't high enough
echo to purchase this item.
pause >nul
goto main

:save
(
echo set level=%level%
echo set health=%health%
echo set money=%money%
echo set exp=%exp%
echo set expmax=%expmax%
echo set str=%str%
echo set def=%def%
echo set wep=%wep%
echo set wepdis=%wepdis%
echo set arm=%arm%
echo set armdis=%armdis%
echo set hpots=%hpots%
echo set spl=%spl%
echo set spldis=%spldis%) >Save.bat
cls
echo Game Saved!
pause >nul
goto main

:exit
cls
echo All unsaved progress will be
echo lost, are you sure? (Y/N)
set /p input=

if %input% == y exit
if %input% == n goto main
goto exit
pause >nul
exit

:levelup
set /a level= %level% + 1
set exp=0
set /a expmax= %expmax% * 150 / 100
cls
echo Congratulations!
echo You are now level %level%!
echo.
pause >nul
goto main

j0y
Posts: 26
Joined: 10 Oct 2015 08:22

Broken Health Potion and Enemy on Batch Rpg

#29 Post by j0y » 10 Oct 2015 15:35

Hey I need help with this (again). I'm making a game for homework and I can't figure out why my enemie's health bar is broken or why the potions cause the command prompt to quit. Here is the code for both of them:

Code: Select all

:fight1
set enehealth=70
if %level% == 2 set enehealth=82
if %level% == 3 set enehealth=83
if %level% == 4 set enehealth=84
if %level% == 5 set enehealth=85
if %level% == 6 set enehealth=86
if %level% == 7 set enehealth=87
if %level% == 8 set enehealth=88
if %level% == 9 set enehealth=99
if %level% == 11 set enehealth=100
if %level% == 12 set enehealth=100
if %level% == 13 set enehealth=100
if %level% == 14 set enehealth=100
if %level% == 15 set enehealth=100
if %level% == 16 set enehealth=100
if %level% == 17 set enehealth=100
if %level% == 18 set enehealth=100
if %level% == 19 set enehealth=100
if %level% == 20 set enehealth=100
if %level% == 21 set enehealth=100

:fight
if %health% GTR 100 set health=100
if %health% LSS 1 goto lose
cls
echo FIGHT
echo -------------------------------------------------
echo Rosanna Hp:%health%/100 Level:%level%
echo Weapon:%wepdis%  Armour:%armdis% Spell:%spldis%
echo -------------------------------------------------
echo Enemy
echo Hp:%enehealth%/100
echo.
echo 1) Attack
echo 2) Drink Potion
echo 3) Spell
echo 4) Flee
echo.
set /p input=Enter:

if %input% == 1 goto attack
if %input% == 2 goto potion
if %input% == 3 goto spell
if %input% == 4 goto flee
goto fight

:attack
set num=%random:~-2%
if %num% GTR %str% goto attack
if %num% LSS 0 goto attack
if %num% == 00 set num=0
if %num% == 01 set num=1
if %num% == 02 set num=2
if %num% == 03 set num=3
if %num% == 04 set num=4
if %num% == 05 set num=5
if %num% == 06 set num=6
if %num% == 07 set num=7
if %num% == 08 set num=0
if %num% == 09 set num=7
cls
echo You take %num% health from
echo the enemy.
pause >nul
set /a enhealth= %enhealth% - %num%
set /a exp= %exp% + %num% * 2
goto enattack

:enattack
if %enhealth% LSS 1 goto win
set num=%random:~-1%
if %num% GTR 7 goto enattack
if %num% LSS 0 goto enattack
set /a num= %num% - %def%
if %num% LSS 0 set num=0
cls
echo The enemy takes %num% health
echo from you.
pause >nul
set /a health= %health% - %num%
goto fight

:spell

set num=%spl%
if %num% GTR %str% goto attack
if %num% LSS 0 goto attack
if %num% == 00 set num=0
if %num% == 01 set num=1
if %num% == 02 set num=2
if %num% == 03 set num=3
if %num% == 04 set num=4
if %num% == 05 set num=5
if %num% == 06 set num=6
if %num% == 07 set num=7
if %num% == 08 set num=0
if %num% == 09 set num=7
cls
echo You cast a spell and take %num% health from
echo the enemy.
echo.
pause >nul
set /a enhealth= %enhealth% - %num%
set /a exp= %exp% + %num% * 2
goto enattack

This is all the code I have done that includes the enemy in the game. As you can see I am trying to increase the enemy's health every time the player levels up. Where have I gone wrong? How do I fix it?

Code: Select all

:potion
cls
echo 1)Drink Potion
echo 2)Back
echo.
set /p input=Enter:

if %input% == 2 goto fight
if %hpots% LSS 1 set goto nopots
if %input% == 1 set hpots= %hpots% - 1
if %input% == 1 %health% + 35
if %input% == 1 goto fight
goto potion

:nopots
cls
echo You have no potions left!
pause >nul
goto fight


This is all the code to do with the potions. When I use the option to drink one, no matter if I have one or if I don't it will
+ was not expected at this time
and then immediately shut down the command prompt. How do I fix this? Please help soon.

TheHunterManX
Posts: 54
Joined: 14 Aug 2015 05:59

Re: Broken Health Potion and Enemy on Batch Rpg

#30 Post by TheHunterManX » 10 Oct 2015 15:43

forgot the set variable
this is your code:

Code: Select all

if %input% == 1 set hpots= %hpots% - 1
if %input% == 1 %health% + 35
if %input% == 1 goto fight

and this is the correct code:

Code: Select all

if %input% == 1 set hpots= %hpots% - 1
if %input% == 1 set health= %health% + 35
if %input% == 1 goto fight

Locked