Announcement

Collapse
No announcement yet.

Syntax Command is Incorrect Problem.

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Syntax Command is Incorrect Problem.

    Could you please tell me what this means and please tell me what i should change in the code to resolve this issue.

    <<Mod edit: Removed corrupted pdf attachment>>
    == jou can copy paste script code in the post or attach large script files as plain text files with the txt extension ==



    batch:
    Code:
    @echo off
    color b0
    : menu 
    cls
    echo Hey! welcome to the game!
    echo 1) start!
    echo 2) how to play
    echo 3) exit
    set /p number=
    
    if %number% == 1 goto startgame
    if %number% == 2 goto findhelp
    if %number% == 3 goto exit
    
    : startgame
    cls
    echo Type your Name:
    set /p name=
    echo Hello %name%
    echo Do you want to start the quiz? (y/n)
    set /p start=
    if %start% == y goto level1
    if %start% == n goto menu
    goto startgame
    
    : findhelp
    cls
    echo Press the number of the answer then hit enter.
    echo go back (y/n)
    set /p menugot o=
    if %menugoto% == y goto menu
    if %menugoto% == n goto exit
    goto help
    
    : exit
    goto exit
    
    : level1
    cls 
    echo okay, lets start.
    echo what is 10 + 10?
    echo 1) 1
    echo 2) 20
    echo 3) 500
    
    set /p answer1=
    if %answer1% ==1 goto wrong1
    if %answer1% ==2 goto correct1
    if %answer1% ==3 goto wrong1
    goto level1
    
    : correct1
    echo You are right! Next level? (y/n)
    set /p NL1=
    
    if %NL1% == y goto level 2
    if %NL1% == n goto menu 
    goto correct 1
    
    : wrong1
    echo Sadly, you were wrong. Retry?(y/n)
    set /p WA1
    if %WA1% == y goto level1
    if %WA1% == n goto menu
    goto wrong1
    
    : level2
    
    cls
    echo Who is on the 100 dollar bill?
    echo 1) Ben Franklin
    echo 2) Micheal Jackson
    echo 3) Homer Simpson
    echo 4) Buster 
    set /p aa=
    if %aa% == 1 goto correct2
    if %aa% == 1 goto wrong2
    if %aa% == 1 goto wrong2
    if %aa% == 1 goto wrong2
    goto level2
    
    : correct2
    cls
    echo YOU WIN THE GAME!
    goto correct2
    
    : wrong2
    cls 
    echo YOU LOST! RETRY GAME? (y/n)
    set/p retry=
    if %retry% == y goto level1
    if %retry% == n goto exit
    Last edited by Rems; 13th January 2012, 16:11.

  • #2
    Re: Syntax Command is Incorrect Problem.

    I couldn't see any error messages in your submission, but I see 2 things that might be a problem:

    First, each jump destination (i.e. ": menu") maybe shouldn't have a fixed space between the colon and the name (i.e. ":menu"). Lose all those spaces.

    Second, you have 2 places where you call "goto exit". Then under the ":exit" jump destination you use the same command again, "goto exit". Delete that "goto exit" statement! That command puts the program in a continual loop calling itself, rather than actually exiting.

    If your posted code was truncated in the message and you want to do something final before exiting altogether, then move the ":exit" statement from the middle to the end of the code, run the final step(s) you want to run, and then make the last line of code simply "exit". If you have nothing else to run, then the last lines should be:

    :exit
    exit

    It's not required to be at the end, but it's easier to follow that way.
    *RicklesP*
    MSCA (2003/XP), Security+, CCNA

    ** Remember: credit where credit is due, and reputation points as appropriate **

    Comment


    • #3
      Re: Syntax Command is Incorrect Problem.

      Yes... i see spaces where there shouldnt be one, i.e. line 30, the word goto is split. Line 56 level2 is split.


      FYI
      If you like you can add animation and delays to the program to make it look as if it's "acting smarter",
      Here is a sample, maybe you like it or not
      Code:
      @echo off
      Set "fcr=0" & Set "bcr=b"
      Set "title=Game"
      
      :menu
      color %bcr%%fcr% & cls
      Set "name=" & echo.
      <nul (Set /P j=Hey! )
      call:titlebar
      echo.welcome to the game!
      echo.
      echo.   1) start!
      echo.   2) how to play
      echo.   3) quit
      echo.
      set /p "number=> Your choice: " & call:titlebar
         if "%number%" EQU "1" goto :startgame
         if "%number%" EQU "2" goto :findhelp
         if "%number%" EQU "3" goto :quit
      goto :menu
      
      :startgame
      cls & echo.
      set /p "name=Type your Name: " & call :titlebar
      :startgame~
      cls & echo.&echo.
      < nul (set /p "echo=Hello %name%, ")
      call:titlebar
      set /p "start=do you want to start the quiz? (y/n) _"
      if /i "%start%" EQU "y" goto :level1
      if /i "%start%" EQU "n" goto :menu
      goto :startgame~
      
      :findhelp
      cls & echo.
      echo Press the number of the answer then hit enter.
      set /p "menugoto=go back (y/n) "
      if /i "%menugoto%" EQU "y" goto menu
      if /i "%menugoto%" EQU "n" goto quit
      call:invalidinput
      goto :findhelp
      
      :quit
      endlocal & cls
      echo.&echo.You have ended the game...
      >nul pause
      goto:menu
      goto:EOF
       
      ----------------------------------------------------------------
      : level1
      setlocal & cls
      Set /a Level=1
      set "choice=" & set "a="
      echo.&echo.&echo.
      < nul (set /p "echo=Ready?, ")
      call:titlebar
      echo.lets start.
      echo.
      echo.what is 10 + 10?
      echo.   1) 1
      echo.   2) 20
      echo.   3) 500
      echo.
      set /p "a=answer: "   =2
      If Not "%a%" LSS "1" If Not "%a%" GTR "3" (
         If "%a%" EQU "2" (call:ca "You are right!"
         ) ELSE call:wa "Sadly, you were wrong.")
      If defined choice endlocal&goto:%choice%
      endlocal
      call:invalidinput
      goto :level1
      ----------------------------------------------------------------
      : level2
      setlocal & cls
      Set /a Level=2
      set "choice=" & set "a="
      echo.&echo.&echo.
      < nul (set /p "echo=okay %name%, ")
      call:titlebar
      echo.the next test.
      echo.
      echo.Who is on the 100 dollar bill?
      echo.   1) Ben Franklin
      echo.   2) Micheal Jackson
      echo.   3) Homer Simpson
      echo.   4) Buster 
      echo.
      set /p "a=answer: "   =1
      If Not "%a%" LSS "1" If Not "%a%" GTR "4" (
         If "%a%" EQU "1" (call:ca "The answer is correct!"
         ) ELSE call:wa "incorrect")
      If defined choice endlocal&goto:%choice%
      endlocal
      call:invalidinput
      goto :level2
      ----------------------------------------------------------------
      : level3
      setlocal & cls
      Set /a Level=3
      set "choice=" & set "a="
      echo.&echo.&echo.
      < nul (set /p "echo=(Hey pssst,)    ")
      for /L %%a in (1,1,3) do call:titlebar
         :: showing message for a short while
         <nul (Set /P j=There is no level %Level%)
         for /L %%a in (1,1,5) do (
         call:titlebar
         >nul ping -n 1 -w "0 0.0.0.1"
         <nul (Set /P j=!)
         )
         echo.&echo.
      set /p "r=Did you play it fair? (y/n) _"
         if /i "%r%" EQU "y" goto :correctfinal
         if /i "%r%" EQU "n" goto :wrongfinal
      endlocal
      call:invalidinput
      goto :level3
      ----------------------------------------------------------------
       
      :correctfinal
      endlocal & cls
      echo.&echo.&echo.&echo.&echo.&echo.
      echo.
      echo.   You know what %name%...
      echo.                           YOU WIN THE GAME!
      echo.&echo.                                 ~ ~ ~
      echo.
      start /MIN mplay32.exe /play /close c:\windows\media\chimes.wav
      >nul pause
      goto:menu
      goto:EOF
      
      :wrongfinal
      endlocal & cls
      echo.&echo.&echo.&echo.&echo.&echo.
      echo.
      echo.   You know what %name%...
      echo.                                   YOU LOST!
      echo.&echo.                                     ~ ~ ~
      echo.
      start /MIN mplay32.exe /play /close "c:\windows\media\chimes.wav"
      set /p "r=   Retry game? (y/n) _"
      if /i "%r%" EQU "y" goto :level1
      >nul pause
      goto:menu
      goto:EOF
      
      
      goto:EOF  --- begin sub routines ---
      
      :wa - wrong answer options
      call:titlebar
      echo.%~1
      :wa~
      set /p "r= Retry? (y/n) _"
      if /i "%r%" EQU "y" (
         set "choice=level%Level%"
         exit /b 0 )
      if /i "%r%" EQU "n" (
         Set "choice=menu"
         exit /b 0)
      call:invalidinput
      goto :wa~
      exit /b 0
      
      :ca - correct answer options
      call:titlebar
      set /a nextLevel=%Level%+1
      echo.%~1
      : ca~
      set /p "r= Next level? (y/n) _"
      if /i "%r%" EQU "y" (
         set "choice=level%nextLevel%"
         exit /b 0 )
      if /i "%r%" EQU "n" (
         Set "choice=menu"
         exit /b 0)
      call:invalidinput
      goto :ca~
      exit /b 0
      
      :invalidinput
      color %bcr%c
      echo\
      <nul (Set /P j=input invalid)
      for /L %%a in (1,1,8) do (
      call:animation
      <nul (Set /P j=.)
      )
      color %bcr%%fcr%
      exit /b 0
      
      :titlebar
      for /L %%a in (1,1,8) do (
      call:animation
      >nul ping -n 1 -w "0 0.0.0.1")
      exit /b 0
         :animation
         Set _title=(Set "_mill=\ ")
         IF DEFINED _mill (call:updtitle) ELSE (%_title%)
         title %title%                   %_mill% & exit /b 0
           :updtitle
           If "%_mill:~-2%"=="\ " (Set "_mill=^|" & exit /b 0)
           If "%_mill:~-2%"=="^|" (Set "_mill=/ " & exit /b 0)
           If "%_mill:~-2%"=="/ " (Set "_mill=--" & exit /b 0)
           %_title% & exit /b 0
       
      End Of Batch
      additionally:
      In this sample I did not only use "goto :labelname" it also make use of "call :labelname". When calling a label the part acts as a sub routine, it returns back to the spot it was called from when it exit. Instead of creating multiple labels for correctAnswer1 to xx and wrongAnswer1 to xx you can make use of just a few subroutines.


      /Rems
      Last edited by Rems; 13th January 2012, 23:54.

      This posting is provided "AS IS" with no warranties, and confers no rights.

      __________________

      ** Remember to give credit where credit's due **
      and leave Reputation Points for meaningful posts

      Comment

      Working...
      X