Reputation: 47
I recently followed some tutorials and learnt how to create and program batch files. I started making a game meant to simulate fighting monsters. One of the mechanics of this game was to be an inventory where once programmed, you'd be able to buy certain items from a store and put them in your inventory which you can already access in battle. The only programmed level so far is the tutorial and only the start of it. What you should be able to do is select an inventory slot when asked, then the computer should run the inventory function which it doesn't seem to do. Some error shows up, then closes the window automatically.If anyone could explain in simple terms why this isn't working and how i can fix it, it would really help me out. Thanks :D Here's my code...
::SETUP
@echo off
title Platformer
color 0a
::Variables
set my_level=0
set money=0
set inventory_slot_1=
set inventory_slot_2=
set inventory_slot_3=
set inventory_slot_4=
set inventory_slot_5=
set current_level=-1
set pin=0
::MONSTER VARIABLES
set monster_level = 0
::MAIN MENU
:main_menu
cls
echo.
echo PPPPP l aaaaa ttttt fffff ooooo rrrr mmmmm eeeee rrrr
echo P P l a a t f o o r r m m m e r r
echo PPPPP l aaaaa t ffff o o rrrr m m m eeee rrrr
echo P l a a t f o o r r m m m e r r
echo P l a a t f ooooo r r m m eeeee r r
echo.
echo 1990 inc.
echo.
echo LVL.%my_level% $%money%
echo ________________________________________________________________________________
echo.
echo 1 - Play
echo 2 - Save
echo 3 - Load
echo.
set /p input=">>> "
if %input%==1 goto level_select
if %input%==2 goto save
if %input%==3 goto load
pause >nul
::LEVEL SELECT
:level_select
cls
echo LVL.%my_level% $%money%
echo ________________________________________________________________________________
echo.
echo 1 - Tutorial
echo 2 - Level 1
echo 3 - level 2
echo 4 - level 3
echo 5 - Boss
echo 6 - BACK
echo.
set /p input=">>> "
if %input%==1 goto tutorial
if %input%==2 goto level_select
if %input%==3 goto level_select
if %input%==4 goto level_select
if %input%==5 goto level_select
if %input%==6 goto main_menu
goto main_menu
pause >nul
::INVENTORY
:inventory
if %~1==rock set %damage%=2
if %~1==mercy set mercy_chance=%RANDOM%*%monster_leve%/32768+1
EXIT /b
::TUTORIAL
:tutorial
cls
echo LVL.%my_level% $%money%
echo ________________________________________________________________________________
echo.
set /a current_level = 0
call:summon_dragon
pause >nul
::Monster -- Dragon
:summon_dragon
set /a monster_level=%current_level%+1
set /a rand=%RANDOM%%%3+1
set /a monster_hp=%monster_level%*3+%rand%
echo A Lvl.%monster_level% Dragon Has Been Summoned
echo What Will You Do?
echo.
echo HP: %monster_hp%
echo.
echo 1 - [ %inventory_slot_1% ]
echo 2 - [ %inventory_slot_2% ]
echo 3 - [ %inventory_slot_3% ]
echo 4 - [ %inventory_slot_4% ]
echo 5 - [ %inventory_slot_5% ]
echo 6 - [ Mercy ]
echo.
set /p input=">>> "
if input==1 callinventory %inventory_slot_1%
if input==2 call:inventory %inventory_slot_2%
if input==3 call:inventory %inventory_slot_3%
if input==4 call:inventory %inventory_slot_4%
if input==5 call:inventory %inventory_slot_5%
if input==6 (
call:inventory mercy
if %mercy_chance%==1 (
set my_level=%my_level%+1
goto win
)
)
set monster_hp=%monster_hp%-%damage%
if monster_hp<=0(
set my_level=%my_level%+1
set current_level=%current_level%+1
goto win
)
EXIT /b
::WIN
:win
cls
echo YOU WIN!
pause >nul
::SAVE
:save
cls
echo LVL.%my_level% $%money%
echo ________________________________________________________________________________
echo.
set /p pin="Pin: "
echo.
if pin==nul(set /p pin = Change Pin: goto save)
(
echo @echo off
echo set my_level=%my_level%
echo set money=%money%
) >> game_saves\%pin%.cmd
echo SAVED
pause >nul
goto main_menu
::LOAD
:load
cls
echo LVL.%my_level% $%money%
echo ________________________________________________________________________________
echo.
set /p pin="Pin: "
echo.
if pin==nul( pause >Invalid Pin goto load)
call game_saves\%pin%.cmd
echo Loaded
pause >nul
goto main_menu
Upvotes: 0
Views: 65
Reputation: 79983
if %~1==rock set %damage%=2
Is probably incorrect. If %~1
is empty, then there will be a syntax error.
You are attempting to set
the variable that is the contents of damage
to 2. Probably this is incorrect. If damage
is not set at this time, you will get an error as cmd
attempts to parse set =2
Go to Start>Programs>Accessories and set yourself a shortcut to Command Prompt
.
Clicking that will put you in to cmd
and you can then navigate about and run the batch by changing to the appropriate directory with cd c:\wherever\your\batch\is
and simply running nameofyourbatchfile.
To exit cmd
, type exit
and to get help on commands type commandname /?
All acions are terminated with Enter
Upvotes: 1