Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
CodingBear
- Posts: 19
- Joined: 26 Dec 2014 16:37
#1
Post
by CodingBear » 16 Apr 2015 13:05
So I'm returning to batch and this code may be a bit dirty as it was written quickly but I'm trying to make a 2 player game and I don't know why the variable for name and health aren't displaying. On the play screen. Like I said its not very organized and kind of confusing cause I want the game to understand what each player is.
Code: Select all
@echo off
title Pimp Kingdom
::Variables
set 1health=100
set damage=10
set 2health=100
set pimpstatus=0
set hoestatus=0
set 2pimpstatus=0
set 2hoestatus=0
:menu
cls
echo Hey, Welcome to Pimp Kingdom where you can either be a pimp and fight
echo unruly hoes or be an unruly hoe and escape your pimps reign or maybe a
echo Pimp vs Pimp or Hoe vs Hoe
pause
goto playerchoose1
:playerchoose1
cls
echo What is the first player?
echo.
echo 1)Pimp
echo 2)Hoe
echo.
set /p playerchoose=">>"
if %playerchoose% == 1 set pimpstatus=1
if %playerchoose% == 2 set hoestatus=1
cls
echo What is your name?
echo.
set /p 1name=">>"
echo %1name%
goto playerchoose2
:playerchoose2
cls
echo What is the second player?
echo.
echo 1)Pimp
echo 2)Hoe
echo.
set /p playerchoose2=">>"
if %playerchoose2% == 1 set 2pimpstatus=1
if %playerchoose2% == 2 set 2hoestatus=1
cls
echo What is your name?
echo.
set /p 2name=">>"
goto player1game
:player1game
if %pimpstatus% == 1 goto player1pimpgame
if %hoestatus% == 1 goto player1hoegame
:player1pimpgame
cls
echo %1name% %1health% %2name% %2health%
echo.
echo 1)attack
echo 2)run
set /p p1choice=">>"
if %p1choice% == 1 goto player2game
if %p1choice% == 2 exit
:player2game
if %2pimpstatus% == 1 goto player2pimpgame
if %2hoestatus% == 1 goto player2hoegame
:player2pimpgame
cls
echo Hi
pause
exit
-
Squashman
- Expert
- Posts: 4488
- Joined: 23 Dec 2011 13:59
#2
Post
by Squashman » 16 Apr 2015 14:58
Put the number at the end of your variable name.
-
CodingBear
- Posts: 19
- Joined: 26 Dec 2014 16:37
#3
Post
by CodingBear » 16 Apr 2015 17:12
ok I'll have to try that thnx for the response why your here (hopefully) can you tell me whats wrong with this
Code: Select all
if %swordstatus% == 1 echo 2) Stab it in the kidney || echo 2) Punch it in the kidney
It doesn't display anything I have also tried |, this is the whole code if you need to look at it
Code: Select all
@echo off
title Monster vs Humans
::Variables
set HHealth=100
set HDamage=10
set MHealth=100
set MDamage=10
set money=100
set swordstatus=0
:name
cls
echo What is your name?
echo.
set /p name=">>"
goto menu
:menu
cls
echo Hello %name%, weclome to Monsters v. Humans what would you like to do?
echo.
echo 1) Battle a monster
echo 2) Shop
echo 3) Go on a quest
echo 4) Exit
echo.
set /p menu=">>"
if %menu% == 1 goto battlemenu
if %menu% == 2 goto shop
if %menu% == 3 goto questboard
if %menu% == 4 exit
:battlemenu
cls
echo Choose a monster to fight!
echo.
echo 1) Monster
echo 2) Exit
echo.
set /p monsterchoice=">>"
if %monsterchoice% == 1 goto battlemonster
if %monsterchoice% == 2 goto menu
:shop
cls
echo Welcome to the shop! Gold %money%
echo ----------------------------------
echo 1)Sword 50
echo 2)Menu
set /p buy=">>"
if %buy% == 1 goto buysword
if %buy% == 2 goto menu
:buysword
cls
set /a money=%money%-50
set swordstatus=1
echo You have boughten a sword for 50 gold
pause
goto shop
:questboard
cls
echo Quests coming soon
pause
goto menu
:battlemonster
cls
if %MHealth% LEQ 0 goto victory
echo Human %HHealth% Monster %MHealth%
echo KILL IT KILL IT WITH FIRE
echo.
echo 1) Punch it in the throat
if %swordstatus% == 1 echo 2) Stab it in the kidney || echo 2) Punch it in the kidney
echo 3) Run Away
echo.
set /p battlechoice=">>"
if %battlechoice% == 1 goto hattack
if %battlechoice% == 2 goto swordattack
if %battlechoice% == 3 goto chickenout
:hattack
set /a MHealth=%MHealth%-%HDamage%
goto battlemonster
:chickenout
cls
echo Wow you suck
pause
goto menu
:victory
cls
echo YOU KILLED IT!! CONGRATZ MAN (shame you didn't use fire though)
set MHealth=100
pause
goto menu
-
Ed Dyreen
- Expert
- Posts: 1569
- Joined: 16 May 2011 08:21
- Location: Flanders(Belgium)
-
Contact:
#4
Post
by Ed Dyreen » 16 Apr 2015 17:44
CodingBear wrote:ok I'll have to try that thnx for the response why your here (hopefully) can you tell me whats wrong with this
Code: Select all
if %swordstatus% == 1 echo 2) Stab it in the kidney || echo 2) Punch it in the kidney
Code: Select all
if +%swordstatus% EQU 1 (
echo. 2^) Stab it in the kidney
)else echo. 2^) Punch it in the kidney
Code: Select all
2) Punch it in the kidney
Druk op een toets om door te gaan. . .
-
CodingBear
- Posts: 19
- Joined: 26 Dec 2014 16:37
#5
Post
by CodingBear » 16 Apr 2015 17:48
Code: Select all
if +%swordstatus% EQU 1 echo. 2^) Stab it in the kidney ^|^| echo 2^) Punch it in the kidney
It didn't work

-
CodingBear
- Posts: 19
- Joined: 26 Dec 2014 16:37
#6
Post
by CodingBear » 16 Apr 2015 17:52
Hey guys thanks for all the suggestions but I figured it out
Code: Select all
if %swordstatus% == 1 echo 2) Stab it in the kidney
if not %swordstatus% == 1 echo 2) punch it in the kidney
-
Ed Dyreen
- Expert
- Posts: 1569
- Joined: 16 May 2011 08:21
- Location: Flanders(Belgium)
-
Contact:
#7
Post
by Ed Dyreen » 16 Apr 2015 18:00
CodingBear wrote:Hey guys thanks for all the suggestions but I figured it out
Code: Select all
if %swordstatus% == 1 echo 2) Stab it in the kidney
if not %swordstatus% == 1 echo 2) punch it in the kidney
It throws an exception if the varable is unDefined
Code: Select all
set "swordstatus="
if %swordstatus% == 1 echo 2) Stab it in the kidney
if not %swordstatus% == 1 echo 2) punch it in the kidney
and if it's in a code block
Code: Select all
set "swordstatus=1"
(
if %swordstatus% == 1 echo 2) Stab it in the kidney
if not %swordstatus% == 1 echo 2) punch it in the kidney
)
the code I posted does not
Code: Select all
set "swordstatus="
(
if +%swordstatus% EQU 1 (
echo. 2^) Stab it in the kidney
)else echo. 2^) Punch it in the kidney
)
Code: Select all
2) Punch it in the kidney
Druk op een toets om door te gaan. . .
-
CodingBear
- Posts: 19
- Joined: 26 Dec 2014 16:37
#8
Post
by CodingBear » 17 Apr 2015 12:25
Squashman wrote:Put the number at the end of your variable name.
Thanks it works now:)