Solved Need help with small batch game

March 2, 2017 at 16:30:47
Specs: Windows 10, 2GHz 4GB
I am attempting to make a small batch game. It involves a person i know in real life and is made for fun to hopefully help myself learn how to script better. I am having trouble with the goto Pre command after the first battle and win screen. It will goto win, pause, goto prompt for 1 or 2, and then it acts like it clears the screen and after something is pressed it closes. Perhaps i have some inputs or variables wrong, also it goes to the lose screen sometimes as well. Not sure if the provided code does but it would occasionally as i tried to change the script, as if it was ignoring to goto command. Thanks for the help, any input is appreciated.

Also i know xp and cash isn't implemented yet, i am not sure how to yet, i followed a short tutorial for the beginning so i could learn some of the commands and lingo. If any knowledge on how to integrate the xp and cash system input on it would be appreciated.

@echo off
setlocal EnableDelayedExpansion
title Batch Game 1

::Stats
set hp=50
set Dhp=50
set xp=1
set Dxp=1
set cash=500
set hp2=100
set Dhp2=100
goto intro

:Intro
cls
echo What will you be called?
set /p name=
echo Ah so %name%, are you prepared for what lies ahead? Yes or No?
set /p yesno=
if %yesno% == yes goto Battle
if %yesno% == no goto quit

:Battle
cls
if %hp% leq 0 goto Lose
if %Dhp% leq 0 goto Win
echo %name% %hp% VS Dillard %Dhp%
echo.
echo Press P to Punch
echo Press K to Kick
echo.
set /p option=
if %option% == p goto punch
if %option% == k goto kick


:Punch
set /a Dhp=%Dhp%-%Random% %%10-9%
goto DAttack

:Kick
set /a Dhp=%Dhp%-%Random% %%12-11%
goto DAttack

:DAttack
set /a hp=%hp%-%Random% %%8-5%
goto Battle


:Win
cls
echo Dillard: I... I lost, but... how? It must be true... I am a big stinky puss...
echo ------------------------------------------------------------------------------
echo %name%: Yep. F%%k you bud.
echo.
pause
cls
echo Press 1 to continue, press 2 to quit.
set /p 1pre=
if %1pre% == 1 goto Pre
if %1pre% == 2 exit
goto Pre

:Lose
cls
echo Dillard: Hahahahhehehe, of course I won. With my 6 additional layers of fat no one stood a chance against these upgrades.
echo -------------------------------------------------------------------------------------------------------------------------
echo %name%: I should have known...
pause
exit

:Pre
cls
echo So you defeated Dillard?
echo Well you thought.
echo It turns out he's stinker than we thought, hes back, and uglier than ever.
echo.
echo.
echo %name%: My god, I knew there was a disbalance in the realm.
echo He will see his end once and for all!
goto Intro2

:Intro2
echo So are you ready for the next fight?
echo He will be more powerful this time. As are you.
cls
set /p Yesno2=
if %Yesno2% == Yes goto Battle2
if %Yesno2% == No echo Well your a stink puss
if %Yesno2% == No pause

:Battle2
cls
if %hp2% leq 0 goto Lose2
if %Dhp2% leq 0 goto Win2
echo %name% %hp2% VS Dillard %Dhp2%
echo.
echo Press P to Punch
echo Press K to Kick
echo Press D for Dagger
echo.
set /p option2=
if %option2% == p goto punch2
if %option2% == k goto kick2
if %option2% == d goto Dagger

:Punch2
set /a Dhp2=%Dhp2%-%Random% %%15-13%
goto DAttack2

:Kick2
set /a Dhp2=%Dhp2%-%Random% %%17-13%
goto DAttack2

:Dagger
set /a Dhp2=%Dhp2%-%Random% %%18-16%
goto DAttack2

:DAttack2
set /a hp2=%hp2%-%Random% %%10-6%
goto Battle2


See More: Need help with small batch game

Report •

#1
March 6, 2017 at 03:50:34
The problem you're having is caused by you having a variable that starts with a number. The command processor mistakes this for being %1, meaning an argument supplied from outside the script or sub.
I personally avoid using numbers in variables, unless I use expanded variables (!variable! instead of %variable%).
Simply change it into something that doesn't start or end with a number and you should be good to go.

Also:

In :Battle you automatically go to :Punch if you enter anything else than the two options. I suggest you add a goto :Battle after:

if %option% == p goto punch
if %option% == k goto kick

Another thing to keep in mind when processing input, is that any character can be provided, meaning if nothing is provided the window just closes due to a syntax error. A good way to prevent this is by adding quotes in the IF statement:

if /i "%option%"=="p" goto punch
if /i "%option%"=="k" goto kick

You may also add the /i switch, which I've done in the example. This makes the if ignore whether it's lower case or upper case letters, so you can provide both a P or a p and still get away with it.

One more thing that's handy to know is that you can use parentheses to create an IF clause, so that you don't have to use an IF for each command you want to execute if the given statement is true:

if /i "%Yesno2%"=="No" (
        echo Well your a stink puss
        pause
)
if /i "%Yesno2%"=="Yes" (
        goto Battle2
)

As for implementing xp and money, you just do simple math wherever you need it:

set /a xp+=500

or
set /a money+=4000

You can save these values to a file by doing:
(
echo money=%money%
echo xp=%xp%
)>savegame.txt

Then load them back in by doing:

for /f "tokens=1,* delims==" %%A in (savegame.txt) do set %%A=%%B


Voila! You can now close the game and open it again without losing your progress.

Don't worry if plan A fails, there are 25 more letters in the alphabet, not to mention upper and lower case ones ;)

message edited by RainBawZ


Report •

#2
March 16, 2017 at 05:46:39
✔ Best Answer
I hope my 200kb game will give you some sample info:

http://pastebin.com/qhgTGvU5

It also contains a save&load menu which would come in handy later on.

Here is my upgraded version of yours:

-------------------------------------------------------------------------

@echo off&setlocal EnableDelayedExpansion&title Batch Game 1
:presets
set hp=50
set Dhp=50
set xp=1
set Dxp=1
set cash=500
set hp2=100
set Dhp2=100
:Intro
cls
echo What will you be called?
set /p name=
if '%name%'=='' goto Intro
cls
echo Ah so %name%, are you prepared for what lies ahead?
echo.
echo [1] Yes
echo [2] No
choice /c 12 /n >nul
if %errorlevel% equ 1 goto Battle
if %errorlevel% equ 2 goto quit
:Battle
cls
::moved enemy hp-check up so its in your favour, since you attack first
if %Dhp% leq 0 goto Win
if %hp% leq 0 goto Lose
echo %name% -[%hp%] VS Dillard - [%Dhp%]
echo.
echo [1] Punch
echo [2] Kick
choice /c 12 /n >nul
if %errorlevel% equ 1 goto punch
if %errorlevel% equ 2 goto kick
:Punch
set /a temp=%Random:~3,1%
::dmg between 5-9
if %temp% lss 5 goto Punch
set /a Dhp=%Dhp%-%temp%
goto DAttack
:Kick
set /a temp=%Random:~3,2%
::dmg between 0-11
if %temp% gtr 12 goto Kick
set /a Dhp=%Dhp%-%temp%
:DAttack
set /a temp=%Random:~3,1%
::dmg between 5-8
if %temp% lss 5 goto DAttack
if %temp% gtr 8 goto DAttack
set /a hp=%hp%-%temp%
goto Battle
:Win
cls
echo Dillard: I... I lost, but... how? It must be true... I am a big stinky puss...
echo ------------------------------------------------------------------------------
echo %name%: Yep. F%%k you bud.
echo.
pause>nul
cls
echo [1] continue
echo [2] quit
choice /c 12 /n >nul
if %errorlevel% equ 1 goto Pre
if %errorlevel% equ 2 exit /b
:Lose
cls
echo Dillard: Hahahahhehehe, of course I won. With my 6 additional layers of fat no one stood a chance against these upgrades.
echo -------------------------------------------------------------------------------------------------------------------------
echo %name%: I should have known...
pause>nul
exit /b
:Pre
cls&echo So you defeated Dillard?&pause>nul
cls&echo Well you thought.&pause>nul
cls&echo It turns out he's stinker than we thought, hes back, and uglier than ever.&pause>nul
cls&echo %name%: My god, I knew there was a disbalance in the realm.&pause>nul
cls&echo He will see his end once and for all!&pause>nul
:Intro2
cls&echo So are you ready for the next fight?&pause>nul
cls&echo He will be more powerful this time. As are you?
echo [1] yes
echo [2] no
choice /c 12 /n >nul
if %errorlevel% equ 1 goto Battle2
if %errorlevel% equ 2 goto echo Well your a stink puss&pause>nul
:Battle2
cls
::moved enemy hp-check up so its in your favour, since you attack first
if %Dhp2% leq 0 goto Win2
if %hp2% leq 0 goto Lose2
echo %name% %hp2% VS Dillard %Dhp2%
echo.
echo [1] Punch
echo [2] Kick
echo [3] Stab
choice /c 123 /n >nul
if %errorlevel% equ 1 goto Punch2
if %errorlevel% equ 2 goto Kick2
if %errorlevel% equ 3 goto Stab
:Punch2
set /a temp=%Random:~3,2%
::dmg between 13-15
if %temp% lss 13 goto Punch2
if %temp% gtr 15 goto Punch2
set /a Dhp2=%Dhp2%-%temp%
goto DAttack2
:Kick2
set /a temp=%Random:~3,2%
::dmg between 8-20
if %temp% lss 8 goto Kick2
if %temp% gtr 20 goto Kick2
set /a Dhp2=%Dhp2%-%temp%
goto DAttack2
:Stab
::gives output 0 or 1 since %random% size is between 0 and 32767
set /a temp=%random%*2/32767
::dmg between 0 or 30
if %temp% equ 1 set /a Dhp2=%Dhp2%-30
:DAttack2
set /a temp=%Random:~3,2%
::dmg between 10-15
if %temp% lss 10 goto DAttack2
if %temp% gtr 15 goto DAttack2
set /a hp2=%hp2%-%temp%
goto Battle2

-------------------------------------------------------------------------

Would you like me to add a save and load option?

Simple solutions are often the best

message edited by hidde663


Report •
Related Solutions


Ask Question