Goto was unexpected at this time by starter serial window 7

This code is designed to resemble a simpler version of the Pokemon gameplay. I only encoded the attacks. I thoroughly tested and found that the error message (Goto was unexpected at this time) when the user confirmed his attack. A WARNING!! The code is 96 lines long. In the end, I will put a problem section so you can skip this first huge piece.

@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 

Problem:

 :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 

The code here is great, but once I'm here, it does not expect goto commands. Can anyone fix this beef? (Note: β€œEquipment” is just an example. None of the attacks work.) EDIT: if the user puts β€œYes”, β€œNo”, gibberish or nothing, it still delivers the same error message (goto was unexpected at that time )

+7
source share
4 answers

You must put it in quotation marks:

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

Or rather, if you do not want it to be case sensitive:

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

Your problem is that this line:

 set /p accept=Yes/No? 

DOES NOT use the same variable name:

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

The above variables have "ccc", but the first is "cc"

EDIT

Hi, user1205760; I have time to spend, so I take your program and make it a little smaller. This is my version:

 @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 
+3
source

If the user does not enter anything, If lines are likely to be evaluated something like this:

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

which is syntactically incorrect. I would suggest initializing accept before the set /p command with some default value:

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

Thus, if the user simply presses Enter, the accept variable will keep the default value, and the subsequent If will not fail.

+2
source

Sorry,
This is just a question for downvotes.
People who ask are simply NOT SURE the problem should be in THIS PART.

eg.

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

If I just send this line:

 if %a%==1 echo yes 

Then EVERYONE KNOW THAT THE PROBLEM?


Remember that for a variable, such as% abc%, it is better to use it with ", [or {to prevent an error message.


eg.

 set /p abc= 

and the user does not enter anything.
Then the following line should be:

 if %abc%==1 echo Hi 

But it became:

 if ==1 echo Hi 

as "% abc%" == ""
But with "" he will become

 if ""=="1" echo Hi 

And "does not match" 1 ".
Got it?


EDIT ---

If you are using Windows 7 (or other versions), you can also try the following:

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

^ just exits the "pipe" ( | ).

Hope this will be helpful for you!

-one
source

All Articles