2017-01-04 123 views
-2

我想保存一個遊戲,它會卡住。當我按ENTER它會留下一個空白點。有人在我的劇本中看到錯誤嗎?批處理如果存在命令

@echo off 
:saveload 
title player movement 
color 0f 
cls 
set /a health=10 
if exist saves.txt (
    < saves.txt (
     set /p weapon= 
     set /p armorh= 
     set /p armorc= 
     set /p armorl= 
     set /p armorf= 
     set /p bow= 
     set /p gold= 
     set /p dmgweapon= 
     set /p dmgbow= 
     set /p prtah= 
     set /p prtac= 
     set /p prtal= 
     set /p prtaf= 
     set /p name= 
    ) 
    goto :varsetup 
) else (
    echo to first begin we need to get your name! 
    set /p name=What is your name?: 
    (
     set /p armorh=n/a 
     set /p armorc=n/a 
     set /p armorl=n/a 
     set /p armorf=n/a 
     set /p bow=n/a 
     set /p gold=10 
     set /p dmgweapon=1 
     set /p dmgbow=0 
     set /p prtah=0 
     set /p prtac=0 
     set /p prtal=0 
     set /p prtaf=0 
     set /p name=%name% 
    ) > saves.txt 
    goto :saved 
) 
:saved 
+0

嗯這似乎是我的評價不包含正確的代碼,我沒有包括四個空格,但它不會工作,如果有人能解決這個問題我會很感激的是 – Juggler

+1

您需要正常文本和代碼塊之間的空白行。無論如何,在'set/p name ='之後的'else'分支中,而不是'set/p foo = bar',只要我有你的意圖,你需要聲明'echo bar'; '如果存在'應該不是這裏的問題... – aschipfl

+0

非常感謝! – Juggler

回答

0

set /p name=後您的else分支,而不是set /p foo=bar需要說明echo bar,據我得到了你的意圖。 if exist不應該是這裏的問題。這裏是固定的代碼:

@echo off 
:saveload 
title player movement 
color 0f 
cls 
set /a health=10 
if exist "saves.txt" (
    < "saves.txt" (
     set /p weapon= 
     set /p armorh= 
     set /p armorc= 
     set /p armorl= 
     set /p armorf= 
     set /p bow= 
     set /p gold= 
     set /p dmgweapon= 
     set /p dmgbow= 
     set /p prtah= 
     set /p prtac= 
     set /p prtal= 
     set /p prtaf= 
     set /p name= 
    ) 
    goto :varsetup 
) else (
    echo to first begin we need to get your name! 
    set /p name=What is your name?: 
    (
     echo n/a 
     echo n/a 
     echo n/a 
     echo n/a 
     echo n/a 
     echo 10 
     echo 1 
     echo 0 
     echo 0 
     echo 0 
     echo 0 
     echo 0 
     echo %name% 
    ) > "saves.txt" 
    goto :saved 
) 
:saved