2012-03-19 9 views
7

このコードは、ポケモンバトルゲームプレイのより単純なバージョンに似ています。私は攻撃をコード化しました。私は徹底的にテストしましたが、ユーザーが攻撃を確認したときにエラーメッセージ(この時点ではGotoは予期しなかったものです)が見つかりました。警告!!コードは96行です。最後に、私は問題のセクションを置くので、この最初の巨大なチャンクをスキップすることができます。この時点でGotoは予期しなかったバッチウィンドウ7のスターター

@echo off 
Set H1=20 
Set A1=8 
Set D1=6 
Set S1=5 
Set H2=14 
Set A2=5 
Set D2=4 
Set S2=8 
:Begin 
CLS 
Echo Bulbasur 
Echo %H2%/14  /\  
Echo   (__) ___ 
Echo   l __lo.ol 
Echo   l_\ l_\" 
Echo.   
Echo  _ 
Echo */\ 
Echo \\l ) 
Echo \\__l Charmander 
Echo    %H1%/20 
Echo -Attack -Capture 
Echo -Item -Run 
Set /p Move=Action? 
If %move%==Attack goto Attack 
If %move%==Catpure goto capture 
If %move%==Item goto Item 
If %move%==Run Goto Run 
Echo I'm sorry, Charmander can't do that. 
Pause 
goto Begin 
:Attack 
ClS 
Echo Attacks 
Echo 1)Tackle 
Echo 2)Growl 
Echo 3)Ember 
Echo 4)Scratch 
Set /p attack=Which one? 
If %attack%==Tackle goto Tackle 
If %attack%==1 goto Tackle 
If %attack%==Growl Goto Growl 
If %attack%==2 goto Growl 
If %attack%==Ember goto Ember 
If %attack%==3 goto Ember 
If %attack%==Scratch goto Scratch 
If %attack%==4 goto Scratch 
If %attack%==Cancel goto Begin 
Echo I didn't get that 
Goto Attack 
:Tackle 
CLS 
Echo Tackle Hits The opponent where it hurts. EVERYWHERE. 
Echo Do you want to? 
set /p accept=Yes/No? 
If %acccept%==Yes goto Combat 
If %acccept%==No goto Begin 
Echo I didn't get that. 
goto Tackle 
:Growl 
CLS 
Echo Growl lowers the opponents attack. 
Echo Do you want to? 
set /p accept=Yes/No? 
If %acccept%==Yes goto Status 
If %acccept%==No goto Begin 
Echo I didn't get that. 
goto Growl 
:Scratch 
CLS 
Echo Scratch hits the foe with a claw. 
Echo Do you want to? 
set /p accept=Yes/No? 
If %acccept%==Yes goto Combat 
If %acccept%==No goto Begin 
Echo I didn't get that. 
goto Scratch 
:Ember 
CLS 
Echo Ember hits the opponent with a small fire. 
Echo Do you want to? 
set /p accept=Yes/No? 
If %acccept%==Yes goto Combat 
If %acccept%==No goto Begin 
Echo I didn't get that. 
goto Ember 
:Combat 
CLS 
If NOT %attack%==Growl If NOT %attack%==2 set /a H2=%H2%-(%A1%^2/%D2%) 
set /a H1=%H1%-(%A2%^2/%D1%) 
goto Begin 
:Status 
CLS 
Set /a A1=%A1%-1 
goto Combat 

問題エリア:

:Tackle 
CLS 
Echo Tackle Hits The opponent where it hurts. EVERYWHERE. 
Echo Do you want to? 
set /p accept=Yes/No? 
If %acccept%==Yes goto Combat 
If %acccept%==No goto Begin 
Echo I didn't get that. 
goto Tackle 

コードをここに罰金取得しますが、私はここにいると、それが後藤のコマンドを期待していません。誰もがこの牛肉を修正することができますか?編集:ユーザーが「はい」、「いいえ」、不器用、または何も入力しなかった場合でも、同じエラーメッセージが表示されます(この時点では予期せぬものでした)。 )

+7

私はdownvotesについて不思議です。質問者はコードを掲示し、問題領域の例を選び出し、エラーメッセージを出した。私には良い質問のようです。バッチファイルでは軽蔑ですか?それは質問が良いかどうかに影響を与えるべきではありません。 –

+0

@WesleyPetrowski、おそらく彼は彼の全体のスクリプトを投稿した。そして、問題のあるコードの追加コピーを投稿しました。彼は問題のあるコードを掲載しているだけであったはずです。 – mikerobi

+0

'%%move%== Catpure goto capture'私は知っている、その猫は優しいですが、これはtypoです^^ – Stephan

答えて

2

ユーザーが何も入っていない場合は、あなたのIfラインは、おそらくこのような何かに評価:

… 
If ==Yes goto Combat 
If ==No goto Begin 
… 

文法的に間違っていました。ユーザーは単にEnterヒットした場合、accept変数はdefault値を保持し、その後ifがで終わるません、

… 
set accept=default 
set /p accept=Yes/No? 
if … 

その方法を:私はいくつかのデフォルト値とset /pコマンドの前にacceptを初期化することをお勧めエラー。

+1

または%accept%がnullの場合にIF == YESの前にテストを設定してください - 'IF。%accept%==のように見えるかもしれません。 goto xxxx ... ' – RobW

+0

あなたのアイテムの周りに引用符を使って比較することもできますので、If "" == "はい"と評価されます。 Andriyが推奨するデフォルト値を使用することをお勧めします。 –

3

あなたの問題は、この行ということです:変数の上

If %acccept%==Yes goto Combat 
If %acccept%==No goto Begin 

「CCC」が、最初の1だけ「のccを持っている:

set /p accept=Yes/No? 

は、これらのものがあることと同じ変数名を使用していません「

EDIT

こんにちは、使用r1205760;私は費やす時間があるので、私はあなたのプログラムを取って、やや小さくしました。これは私のバージョンです:

@echo off 

Setlocal EnableDelayedExpansion 
Set Actions=Attack Capture Item Run 
Set Attacks=Tackle Growl Ember Scratch Cancel 
Set i=0 
For %%a in (%Attacks%) do set /A i+=1 & set Attack[!i!]=%%a 

Set H1=20 
Set A1=8 
Set D1=6 
Set S1=5 
Set H2=14 
Set A2=5 
Set D2=4 
Set S2=8 

:Begin 
:Cancel 
CLS 
Echo Bulbasur 
Echo %H2%/14  /\  
Echo   (__) ___ 
Echo   l __lo.ol 
Echo   l_\ l_\" 
Echo.   
Echo  _ 
Echo */\ 
Echo \\l ) 
Echo \\__l Charmander 
Echo    %H1%/20 
Echo -Attack -Capture 
Echo -Item -Run 
Set /p Move=Action? 
For %%a in (%Actions%) do if /I %move%==%%a goto %move% 
Echo I'm sorry, Charmander can't do that. 
Pause 
goto Begin 

:Attack 
Cls 
Echo Attacks 
For %%a in (1 2 3 4) do echo %%a)!Attack[%%a]! 
Set /p attack=Which one? 
for %%a in (1 2 3 4) do if %attack%==%%a set attack=!Attack[%%a]! 
for %%a in (%Attacks%) do if /I %attack%==%%a goto %attack% 
Echo I didn't get that 
Pause 
Goto Attack 

:Tackle 
call :Confirm Tackle Hits The opponent where it hurts. EVERYWHERE. 
If %accept%==Yes goto Combat 
goto Begin 

:Growl 
call :Confirm Growl lowers the opponents attack. 
If %accept%==Yes goto Status 
goto Begin 

:Ember 
call :Confirm Ember hits the opponent with a small fire. 
If %accept%==Yes goto Combat 
goto Begin 

:Scratch 
call :Confirm Scratch hits the foe with a claw. 
If %accept%==Yes goto Combat 
goto Begin 

:Status 
Set /A A1-=1 
:Combat 
If /I NOT %attack%==Growl set /A H2=H2-(A1^2/D2) 
set /A H1=H1-(A2^2/D1) 
goto Begin 

:Confirm 
Cls 
Echo %* 
Echo Do you want to? 
set /p accept=Yes/No? 
For %%a in (Yes No) do if /I %accept%==%%a exit /B 
Echo I didn't get that. 
Pause 
goto Confirm 
+0

これは怪我をする可能性があります。ナイスキャッチ。 –

6

あなたが引用符でそれを置く必要があります:

if "%accept%"=="yes" goto combat 
if "%accept%"=="no" goto begin 

か、むしろそれは、大文字と小文字を区別したいいけない場合:

if /i "%accept%"=="yes" goto combat 
if /i "%accept%"=="no" goto begin 
+0

本当に*あなたには気を付けなくてはいけませんが、あなたは確かにそれを行うことができます。それはおそらく、この問題を解決するための最も普及した方法です(そして、何らかの理由で当時考えていなかったものもあります)。 –

-1

は、
すみません これは単なる下降音です。
IS NOT SUREに尋ねる人は、その問題がその部分にある必要があります。

set a= 
if %a%==1 echo yes 

私はちょうどこのライン投稿する場合:

if %a%==1 echo yes 

はその後、誰もが問題だWHAT知っているだろうか?


エラーメッセージを防止するために、%ABC%、それは{「とそれを使用することをお勧めします[またはのように、変数のために覚えておいてください。


を例えば

set /p abc= 

とユーザーは何も入力しません。
次の行は次のようになります。

if %abc%==1 echo Hi 

しかし、それはなった: "== "%のABCの%" として、"
しかしで "

if ==1 echo Hi 

"、それは

if ""=="1" echo Hi 

そして、 "1 "" に等しくない" になります。
理解していますか?


EDIT ---

は、Windows 7(または他のバージョン)を使用している場合は、これを試してください:

choice /c YN /n /m "Confirm? [Y^|N] 

^だけの "パイプ" をエスケープされ(|)。

希望はあなたに役立ちます!

+0

何が起こっているのですか?私はdownvotesを得て、私のコメントはキャンセルされましたか? – Jamie

関連する問題