2016-03-27 30 views
0

我正在批量挑選自己的冒險遊戲,並且我希望擁有它的統計數據來跟蹤您在遊戲中的表現。我想顯示統計信息,但每次我有一個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

不,絕對不是!所有你需要做的就是在'':colorecho'之前插入'exit/B'或者'goto:EOF' *,同樣在[this comment]中建議(http://stackoverflow.com/questions/36254078/call-function - 未加工/ 36254368#comment60140753_36254078)。 – aschipfl