Page 1 of 1

My batch game is fubar - how come?

Posted: 08 Oct 2012 19:51
by marshall123
Wont work why?????

Code: Select all

@echo off
title RPG
:main
cls
echo Welcome to the game...
echo.
echo 1.start
echo 2.exit
set /p $=enter:

if %$% equ 1 goto start
if %$% equ 2 exit
goto main

:start
cls
setlocal enabledelayedexpansion
set /p name =Enter you name:
if exist QE%name%sav.dll set load=1
goto new

:new
set hp=100
set exp=0
setexptill=60
set gold=50
set lvl=1
set power=4
set powergain=3
set weappower=2
set weapprice=120
set pots=1
set armor=0
goto home

:load
for /f %%a in (QE%name%SAV.dll) do set %%a
set /a temp2=(%hp% * %lvl% + %exp% * %exptill% + %weapprice% + %power% * %weappower%)/(%gold% + %pots% * %powergain%)
if not set %temp1% equ %temp2% set temp3=1
goto home

:death
cls
echo You Died!
echo You Lost some stuff...
set /a exp=%exp% - (%exp% * 65/100)
set hp=1
pause >nul
goto home

:runaway
cls
echo You successfully ran away!
set hp=1
pause >nul
goto home

:levelup
cls
echo Congrats! LEVEL UP!
pause >nul
set /a lvl=%lvl% + 1
set /a exp=%exp - %exptill%
set /a exptill=%exptill% + %exptill% * 66 / 100
set /a power=%power% + %powergain%
set /a powergain=%powergain% + 1
set hp =100
goto save

::# HOME ##############################################

:home
set en1hp=40
set en2hp=80
set en3hp=160
if %exp% geq %exptill% goto levelup
cls
if"%temp3%" equ "1" echo you are a cheater...
echo level %lvl%/          experience %exp%/%exptill%            armor %armor%
echo health %hp%/100       gold %gold%                           potions %potions%
echo.
echo Where do you want to go?
echo.
echo 1.Outside the village
echo 2.shop
echo 3.healer
echo 4.save game
echo 5.exit
echo .
set input=5
set /p input+Enter:
if %input% equ 1 goto out
if %input% equ 2 goto shop
if %input% equ 3 goto healer
if %input% equ 4 goto save
if %input% equ 5 goto exit
goto home

:: # Enemy1 ############################################

:out
set en1hp=40
cls
echo You were attacked by a goblin!
pause >nul
goto fightgoblin

:fightgoblin
cls
echo You have %hp% health
echo Goblin has %en1hp%
echo.
echo 1.Attack
echo 2.Drink potion
echo 3. RUN AWAY!
set input=5
set /p input= Enter:
if %input% equ 1 goto attackgoblin
if %input% equ 2 goto drinkpotgoblin
if %input% equ 3 goto runaway

:attackgoblin
cls
set /a en1hp=%en1hp% - (%power% + %weappower%)
if %en1hp% leq 0 goto killedgoblin
set /a hp-%hp% - (7 - %armor%)
if %hp% leq 0 goto death
goto fightgoblin

:drinkpotgoblin
if %pots% 1ss 1 (
    echo You don't have any potions
        pause >nul
        goto fightgoblin
)
set /a hp = %hp% + 50
set /a pots=%pots% - 1
goto fightgoblin

:killedgoblin
cls
echo YOU KILLED HIM!
echo You gained 7 exp and 6 gold
set /a exp=%exp% + 7
set gold=%gold% + 6
pause >nul
goto out2


:: # enemy 2 ########################################
:out2
cls
echo 1.Go further
echo 2.wait Here
echo 3.go home
set input=5
set /p input=Enter:
if %input% equ 1 goto out3
if %input% equ 1 goto
if %input% equ 1 goto home
goto out2

:out 3
set en2hp=80
cls
echo You have %hp% health
echo skeleton has %en2hp%
echo.
echo 1.attack
echo 2.Drink potion
echo 3. Run Away
set input=5
set /p input=Enter:
if %input% equ 1 goto attackskeleton
if %input% equ 2 goto drinkpotskeleton
if %input% equ 3 goto runaway
goto fightskeleton

:attackskeleton
cls




:: # save ############################################

:save
if"%temp3%"equ"1"(
 cls
 echo You're a cheater, YOU NO SAVE!
  pause >nul
  goto stats
)
echo saving...
set /a temp2=(%hp% * %lvl% + %exp% * %exptill% + %weapprice% + %power% * %weappower%)/(%gold% + %pots% * %powergain%)
(echo hp=%hp%)> QE%name%SAV.dll
(echo exp=%exp%)>> QE%name%SAV.dll
(echo exptill=%exptill%)>> QE%name%SAV.dll
(echo gold=%gold%)>> QE%name%SAV.dll
(echo lvl=%lvl%)>> QE%name%SAV.dll
(echo power=%power%)>> QE%name%SAV.dll
(echo powergain=%powergain%)>> QE%name%SAV.dll
(echo weappower=%weappower%)>> QE%name%SAV.dll
(echo weapprice=%weapprice%)>> QE%name%SAV.dll
(echo pots=%pots%)>> QE%name%SAV.dll
(echo armor=%armor%)>>QE%name%SAV.dll
(echo temp1=%temp1%)>>E%name%SAV.dll

:stats
cls
echo %name% %lvl%
echo %exp%/%exptill% expierience
echo.
echo %hp%/100 health
echo %gold% gold
echo %pots% potions
echo.
echo Your power is %power%
echo Your weapon power is #weappower%
echo.
echo PRESS ANY KEY
pause >nul
goto home

Re: My batch game is fubar - how come?

Posted: 09 Oct 2012 03:12
by abc0502
That what i was able to find:
line 25 : set exptill=60 ...................... [add space between set and exptill]
line 39 : if not %temp1% .................. [remove extra set]
line 78 : if "%temp3% ..................... [add space between if and quotes]
line 89 : Echo . ............................... [change to Echo.]
line 90 : set input=5 ........................ [there is no need for it]
line 91 : set /p input=Enter: ............. [not set /p input+Enter:]
line 126 : hp=%hp% ...................... [not hp-%hp%]
line 156 : set input=5...................... [same as line 90, why???]
line 158 : if %input% equ 1 goto ???? ....... [add where to go?]
line 171 : same as line 90 & 156 ............. [extra set input=5 ...again!]
line 178 : :attackskeleton ...................... [label missing code here]
line 187 : if "%temp3%" equ "1" ............. [add spaces between commands]
line 218 : #weappower% ...................... [change to %weappower%]

Re: My batch game is fubar - how come?

Posted: 09 Oct 2012 06:09
by Squashman
Welcome Marshall,
A lot of basic syntax errors. If you are not using a syntax highlighting editor like Notepad++ I would advise you do so. This would have helped you a lot with seeing the syntax errors because your commands and variables would not be highlighted with a lot of the mistakes you made.

Another good option to debug your code is to turn the ECHO on so you can see what is happening with each line execution. Also throw in some pauses after each set of code and echo your current set of variables you are looking at.

Also, when you are writing long batch files like that break up the code and test each section as you are writing it.

Re: My batch game is fubar - how come?

Posted: 09 Oct 2012 06:17
by phillid
I believe the reason he kept setting the choice to 5 before getting the user's choice was an (accidental) way of clearing it so that if you entered no choice at the prompt, the game wouldn't just use the last choce you entered. Perhaps replace all SETs which set the choice to 5 to

Code: Select all

set "input="


Just an assumption anyway..

Phillid

Re: My batch game is fubar - how come?

Posted: 09 Oct 2012 08:09
by abc0502
phillid wrote:I believe the reason he kept setting the choice to 5 before getting the user's choice was an (accidental) way of clearing it so that if you entered no choice at the prompt, the game wouldn't just use the last choce you entered. Perhaps replace all SETs which set the choice to 5 to

Code: Select all

set "input="


Just an assumption anyway..

Phillid


you are right, this must be the case, cause he repeated it more than once and it can't be a mistake.

Re: My batch game is fubar - how come?

Posted: 09 Oct 2012 20:12
by marshall123
thanks guys ill have yo look at my script and use all of ur ideas if necessary!

Re: My batch game is fubar - how come?

Posted: 09 Oct 2012 20:15
by marshall123
abc0502 was right i did it so that it wouldnt use the last thing u entered and would be set to 5