2016-03-27 18 views
0

私はChoose Your Own Adventureゲームをバッチで行っています。私はあなたのゲームにおけるあなたのやり方を追跡するために、それに統計情報を入れたいと思っています。私は統計情報を表示したいが、clsコマンドがあるたびにそれを行う必要があり、コマンドを頻繁に使用するため、:Statsというブロックを作成したので、必要なときにいつでも呼び出すことができます。それは正常に動作しますが、統計表示後の物語はもはや働いていないようです。私は:colorEchoブロックを保持したいので、プレイヤーは対話、物語、およびコマンドを区別することができます。どのようにこれを修正するための任意のアイデア?コール機能が動作していませんか?

: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 

サイドノート:すべての変数を定義しました。私は確信していた。

expected実際に何が起こる

actual

+1

にコールバックするのを忘れ '終了が起こることになっていただきまし

/b'または 'goto:eof'をあなたの最後に追加しますubroutineなので、 ':Start'は':colorEcho'に入ります。 – dbenham

+0

これはまったく何ですか? –

答えて

-2

は、あなたが他のブロックあなたが忘れてしまった

@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 
+0

あなたの意見で ':derp'ラベルの目的は何ですか?このようなメインルーチンに戻ろうとすると、おそらくネストされた呼び出しの制限を超えてしまうでしょう... – aschipfl

+0

derpラベルが必要です –

+1

いいえ、間違いありません! [このコメント]にも示唆されているように、 'exit/B'や' goto:EOF' *を*::colorecho'の前に挿入するだけです(http://stackoverflow.com/questions/36254078/call-function -not-working/36254368#comment60140753_36254078)。 – aschipfl

関連する問題