0

I'm making a Choose Your Own Adventure game in batch, and I want to have stats in it to keep track of how your doing in the game. I want to display the stats, but I have to do it each time I have a cls command, and because I will have that command often, I made a block called :Stats so I can call it every time I need it. It works fine, but the narrative after the Stats displaying don't seem to be working anymore. I want to keep the :colorEcho block, so the player can differentiate between dialogue, narrative and commands to input a choice. Any ideas on how to fix this?

:Start
::Game goes here.
cls
Echo Please enter your player name.
set /p PlayerName="Player name: "
cls
call :Stats
call :colorEcho 7 "You lay on the cold, hard ground, sleeping away. It's   been 1 month since the Virus spread..."
Echo.
call :colorEcho 7 "The sun rises over the horizon, warming up your dirt-caked body."
Echo . 
pause
exit

:Stats
call :colorEcho A "Current Health = "
call :colorEcho C " %Health%"
Echo.
call :colorEcho A "Hunger = "
call :colorEcho C " %Food%"
Echo.
call :colorEcho A "Thirst = "
call :colorEcho C " %Water%"
Echo.
call :colorEcho A "Infection = "
call :colorEcho C " %Infection%"
Echo. 
call :colorEcho A "Stamina = "
call :colorEcho C " %Stamina%"
Echo.
Echo.
pause

:colorEcho
echo off
<nul set /p ".=%DEL%" > "%~2"
findstr /v /a:%1 /R "^$" "%~2" nul
del "%~2" > nul 2>&1i

Side note: I've defined all the variables. That I made sure of.

Whats supposed to happen:

expected

What actually happens:

actual

aschipfl
  • 33,626
  • 12
  • 54
  • 99

1 Answers1

-2

You forgot to call back to the other block

@echo off
SETLOCAL EnableDelayedExpansion
for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do     rem"') do (
  set "DEL=%%a"
)
title Ace
set Health=100
set Food=100
set Water=100
set Infection=100
set Stamina=100
color A
Echo Welcome, %USERNAME% to Ace, a crudely made Choose-Your-Own-Adventure game. You must complete 

this in one try. 
call :colorEcho A "There is" 
call :colorEcho C " no saving" 
Echo . Are you ready?
Echo Your options are:
call :colorEcho C "================="
Echo.
Echo 1. Yes
Echo 2. No
call :colorEcho C "================="
Echo.
Echo Please enter the number corresponding to your answer.
set /p Answer1="Enter your choice: "
if "%Answer1%" == "1" goto Start
if "%Answer1%" == "2" goto Quit

:Quit
Echo You have chosen to quit.
pause
exit

:Start
::Game goes here.
cls
Echo Please enter your player name.
set /p PlayerName="Player name: "
cls
call :Stats

Echo.
call :colorEcho C "You lay on the cold, hard ground, sleeping away. It's been 1 month since the Virus 

spread"
Echo.
call :colorEcho C "The sun rises over the horizon, warming up your dirt-caked body."
Echo. 
pause
exit

:Stats
call :colorEcho A "Current Health = "
call :colorEcho C " %Health%"
Echo.
call :colorEcho A "Hunger = "
call :colorEcho C " %Food%"
Echo.
call :colorEcho A "Thirst = "
call :colorEcho C " %Water%"
Echo.
call :colorEcho A "Infection = "
call :colorEcho C " %Infection%"
Echo. 
call :colorEcho A "Stamina = "
call :colorEcho C " %Stamina%"
EXIT /B
Echo.
Echo.

:colorEcho
echo off
<nul set /p ".=%DEL%" > "%~2"
findstr /v /a:%1 /R "^$" "%~2" nul
del "%~2" > nul 2>&1i
Alex Hong
  • 95
  • 9
  • What is the purpose of the `:derp` label in your opinion?? if you try to return to the main routine like this, you will probably exceed the limit of nested calls... – aschipfl Mar 28 '16 at 10:51
  • the derp label is neccesary – Alex Hong Mar 28 '16 at 12:04
  • 1
    No, it is definitely not! All you have to do is to insert `exit /B` or `goto :EOF` *before* `:colorecho` as also suggested in [this comment](http://stackoverflow.com/questions/36254078/call-function-not-working/36254368#comment60140753_36254078). – aschipfl Mar 28 '16 at 12:37
  • I realize you can do that. I meant something like that was neccesarry. – Alex Hong Mar 28 '16 at 13:18