fight.bat

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Mattis95
Posts: 8
Joined: 12 Jan 2012 13:04

fight.bat

#1 Post by Mattis95 » 04 Feb 2012 06:35

Hello! Now, I've made a kind of fight simulator in batch, but somehow, the save function doesn't work. Or, it does. But load fails... I can't just send the load part of the file, because it's something else... Therefore, I've uploaded it at MediaFire, here: http://www.mediafire.com/?xwkfyjaonxx41if

If you know what's wrong, please let me know!

jeb
Expert
Posts: 1055
Joined: 30 Aug 2007 08:05
Location: Germany, Bochum

Re: fight.bat

#2 Post by jeb » 04 Feb 2012 18:42

Hi Mattis95,

I see multiple problems ...
First, why you don't post your code? Setting a link isn't very helpful.

It doesn't work. Ah you don't know if the load or the save function fails, but why do you know there is an error?
Do you got a syntax error, a blue screen or an error message?

jeb

Mattis95
Posts: 8
Joined: 12 Jan 2012 13:04

Re: fight.bat

#3 Post by Mattis95 » 05 Feb 2012 00:54

When I try to load the game, it says something like "unexpected goto" and exits. I tried to find where the problem was, and found that it didn't really be in the load part of the file. (Maybe it is, but not what I can see) And therefore I thought you may need the whole game. Also, I thought the game might be too long to post here.

jeb
Expert
Posts: 1055
Joined: 30 Aug 2007 08:05
Location: Germany, Bochum

Re: fight.bat

#4 Post by jeb » 05 Feb 2012 13:31

You should increase your debugging stats :)

First you should add some echo statements, one before the "call FightSave%hojj%.bat"
... one behind
one after the goto stat
one after the first "if %statnum% == 0 goto nostat"

And you will see that the line "if %statnum% == 0 goto nostat" fails, but why ?
Add an echo line with the content of statnum and you will see that it is empty and that is the problem here!

Code: Select all

::SAVE DOESN'T WORK!

@echo off
setlocal enabledelayedexpansion
:top
set def=0
set atk=0
set lol=0
set max=12
set min=6
echo Fight simulator II
pause
goto menu

:menu
cls
title MENU
echo MENU
echo.
echo 1) Start playing
echo 2) Help
echo 3) Options
echo 4) Change Log (May be deleted)
echo 5) Load game
echo 6) Fast game (WILL be deleted)
set /p mch=
if %mch% == 1 goto game
if %mch% == 2 goto help
if %mch% == 3 goto opt
if %mch% == 4 goto changelog
if %mch% == 5 goto load
if %mch% == 6 (
set name=Mattis
set statnum=0
set mon=heyman
set monhp=30
set manhp=40
set maxman=40
set maxmon=30
set potn=3
set maxpot=3
set atk=5
set def=4
goto batmen
)

:load
cls
echo What is the name of the save file? (The in-game name)
set /p hojj=
if not exist FightSave%hojj%.bat goto load
echo Loading...
timeout /t 2 /nobreak >nul
call FightSave%hojj%.bat
goto stat

:game
set statnum=9
cls
echo Hello! What's your name?
set /p name=My name is
echo Which difficulty do you want to play on? (1-3, 1=easy, 3=hard)
set /p dif=
if %dif% == 1 goto dif1
if %dif% == 2 goto dif2
if %dif% == 3 goto dif3
:dif1
set monhp=30
set maxman=50
set maxmon=30
set manhp=50
set potn=3
set maxpot=3
goto stat1
:dif2
set monhp=30
set manhp=40
set maxman=40
set maxmon=30
set potn=3
set maxpot=3
goto stat1
:dif3
set monhp=40
set manhp=40
set maxman=40
set maxmon=40
set potn=2
set maxpot=2
goto stat1
:stat1
title STATS?
echo Ok, %name%. You have to choose your stats.
pause
:stat
if %statnum% == 0 goto nostat
echo You have %statnum% stat points.
title OH YES, STATS!
echo [Defence] %def%
echo [Attack] %atk%
echo [Health] %maxman%
echo Type 1 for attack, 2 for defence and 3 for HP. HP will increase by 2 every time it's chosen.
set /p stch=
cls
if %stch% == 1 goto impatk
if %stch% == 2 goto impdef
if %stch% == 3 (
set /a maxman=%maxman% + 2
set /a statnum=%statnum% - 1
goto stat
)
:impatk
title Improve your attack
set atk=%atk%+1
set /a atk=%atk%
set statnum=%statnum%-1
set /a statnum=%statnum%
goto stat
:impdef
title Improve your defence
set def=%def%+1
set /a def=%def%
set statnum=%statnum%-1
set /a statnum=%statnum%
goto stat
:nostat
title What?! No stat points?
echo You have no stat points, so you will start fighting in a moment...
timeout /nobreak /t 2 >nul
goto fight

:fight
set manhp=%maxman%
cls
title Hmm... What to fight?
echo Time to fight, %name%!
pause
echo But first, what is it for a thing (monster?) you want to fight?
set /p mon=I want to fight a(n)
echo Ok!
pause
cls
echo You find a big, strong %mon%.
title Ohh scary!
cls
goto batmen

:batmen
if %monhp% leq 0 goto yay
if %manhp% leq 0 goto no
cls
title ::::::::BATTLE MENU::::::::
echo    ::::::::BATTLE MENU::::::::
echo.
echo Your hp: %manhp%/%maxman%
echo The %mon%'s hp: %monhp%/%maxmon%
echo You have %potn% pot(s).
echo 1) Attack the %mon%
echo 2) Just defend (nearly the same as skip)
echo 3) Drink a potion
set /p bch=
if %bch% == 1 goto attack
if %bch% == 2 goto defend
if %bch% == 3 goto potion

:attack
title ::::ATTACK::::
set /a mandmg=%random% %% (max - min + 1)+min
echo You attack the %mon% and deal %mandmg%+%atk% hp.
pause
if %monhp% leq 0 goto no
set /a monhp=%monhp% - %mandmg% - %atk%
set /a mondmg=%random% %% (max - min + 1)+ min
echo The %mon% attacks you and deals %mondmg%-%def%!
set /a manhp=%manhp% - 10 + %def%
set /a lol=%lol% + 1
pause
goto batmen

:defend
title ::::DEFEND::::
echo You defend.
pause
set /a mondmg=%random% %% (max - min + 1)+ min
echo The %mon% attack you and deals %mondmg%-%def%.
set /a manhp=%manhp% - %mondmg% + %def%
pause
goto batmen
:potion
title ::::POTION::::
echo You have %potn% potions. Do you really want to use one?
set /p yn=(yes/no)
if %yn% == no goto batmen
echo Ok, you drink one and refill your hp by 10.
pause
echo If it goes over %maxman%, it will stop at %maxman%.
set /a manhp=%manhp% + 10
if %manhp% gtr %maxman% set manhp=%maxman%
pause
goto batmen
:no
cls
title lose...
echo Sorry, really sorry.
pause
echo You... Lost!
pause
echo.
echo Do you want to play again?
set /p yn=(yes/no)
if %yn% == yes goto top
if %yn% == no exit

:yay
cls
echo You won!
pause
goto level

:level
echo Pada-pam-pam-pam-paaaa!!!
pause
echo You gained a level.
set /a lvl=%lvl% + 1
set /a min=%min% + 2
set /a max=%max% + 2
set /a maxman=%maxman% + 5
set /a maxmon=%maxmon% + 10
set /a monhp=%maxmon%
set /a manhp=%maxman%
set manhp=%maxman%
set monhp=%maxmon%
set /a statnum=%statnum% + 4
set potn=%maxpot%
echo Do you want to save?
set /p yn=(yes/no)
if %yn% == yes goto save
goto stat

:save
echo Do you realy want to save?
set /p yn=(yes/no)
if %yn% == no goto batmen
echo set name=%name% >> FightSave%name%.bat
echo set lvl=%lvl% >> FightSave%name%.bat
echo set lol=1 >> FightSave%name%.bat
echo set atk=%atk% >> FightSave%name%.bat
echo set def=%def% >> FightSave%name%.bat
goto stat
:help
cls
title ::::HELP::::
echo This is a fighting simulator. It's v. 1.0.1.
pause
echo It's (not) all about fighting.
pause
echo It's (not) a fierce battle on life and death. (Or, yes it is)
pause
echo It's (not) just about typing 1, 2, 3 etc. (Not not really, but nearly...)
pause
echo See readme.txt if you want to know more, in big is this not hard to learn and not much to read... Or?
pause
goto menu

:opt
cls
title ::::OPTIONS::::

:changelog
cls
echo Fight version 1.2.1
echo Maked the game, then it really SUCKED!
pause
echo.
echo Fight version 1.3.5
echo I called it Fight 2. It got a lot better coding, but... It was not so hard.
echo I also added the difficulties and made the potions work.
pause
echo.
echo Fight version 1.5.9
echo It's still not done... But levels will be added!
pause
goto menu

Mattis95
Posts: 8
Joined: 12 Jan 2012 13:04

Re: fight.bat

#5 Post by Mattis95 » 07 Feb 2012 08:02

Thanks, jeb! That did the trick.

Post Reply