2016-02-16 27 views
0

你好我正在Windows批處理中創建一個基本的基於文​​本的冒險遊戲,我不能在用戶輸入中有空格。帶空格的用戶輸入(批量處理)

我的代碼是:

:quest1 
cls 
echo MUM: %PlayerName%, your breakfast is ready!!! 
set /p PlayerInput1=">" 

if %PlayerInput1%=="look around" echo you are in your bedroom upstairs in your house, in %PlayerHome% 

與PlayerInput1我希望用戶輸入環顧四周,但是當我嘗試運行它,它說: 各地==「東張西望」在這個時候意外

如何解決這個

+1

奇怪的是,你會把引號放在字符串比較的一邊,以保護空格而不是其他字符。 – Squashman

回答

1
:quest1 
cls 
echo MUM: %PlayerName%, your breakfast is ready!!! 
set /p PlayerInput1=">" 

if "%PlayerInput1%" =="look around" (echo "you are in your bedroom upstairs in your house, in" "%PlayerHome%") 

如果你忘記了「%PlayerInput1%」中的引號,並且echo不需要在()之間,但是是一種好的做法。 *感謝@Dennisvagils *

+2

括號雖然是一種很好的做法,但不需要在同一行上。 –

+0

謝謝@DennisvanGils的提示 –

+1

沒問題。順便說一下,最好將你的回答更新爲「回聲需要」,「更好」 –

1

認沽串您variavle之間太:

set /p "PlayerInput1=^> " 

if "%PlayerInput1%"=="look around" echo you are in your bedroom upstairs in your house, in %PlayerHome%