GOTO wont work anymore? Im so lost

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Orion
Posts: 6
Joined: 22 Aug 2015 18:39

GOTO wont work anymore? Im so lost

#1 Post by Orion » 24 Oct 2015 16:31

Is there like a limit to the amount of times GOTO can be used, I use it frequently in the game Ive been working on such as

Code: Select all

ECHO.
ECHO blah blah blah
ECHO.
PAUSE
GOTO WHATEVER
:WHATEVER
ECHO.
ECHO blah blah blah

GOTO has always worked up until this point, I cant figure out what is wrong for the life of me.


:XENO10VALUE
SET /a "XenologyValue=%Int%+10"
SET /a "HUIntSkillValue=%XenologyValue%"
ECHO Xenology skill value is %XenologyValue%
PAUSE
GOTO CHARCREATIONPART2
:CHARCREATIONPART2
ECHO *******************************************************
ECHO.
ECHO.
ECHO Lets recap...
ECHO Here is what you have created so far...
ECHO.
ECHO.
ECHO Name: %CHARNAME%
ECHO Race: %CHARRACE%
ECHO.
ECHO Atrributes
ECHO.
ECHO Hp: %Hp%
ECHO Str: %Str%
ECHO Spd: %Spd%
ECHO Int: %Int%
ECHO.
ECHO Skills
ECHO.
ECHO Hp Skill chosen: %HUHpSkill% : %HUHpSkillValue%
ECHO Str Skill chosen: %HUStrSkill% : %HUStrSkillValue%
ECHO Spd Skill chosen: %HUSpdSkill% : %HUSpdSkillValue%
ECHO Int Skill chosen: %HUIntSkill% : %HUIntSkillValue%
ECHO.
ECHO.
PAUSE
GOTO STUPIDPIECEOFSHITCODE
:STUPIDPIECEOFSHITCODE

this is where it refuses to go to the next piece. instead it acts like I have a PAUSE and then thats it. after hitting any key at the prompt of PAUSE, it keeps on saying 'THIS' is not a recognizeable external or internal command, blah blah blah. which ive never had the rest of the game do that. it always goes right to whatever goto says to. I am so lost. So confused. I just want to fix this part. Also if I take away PAUSE, take away the GOTO and the next section, it acts like I have PAUSE anyways, then crashes. Normally If I dont add PAUSE, it ECHO's then exits. Thats why i always use PAUSE. The current file is at 374kb if that matters, and the code is extremely long. [/b]

Code: Select all

ECHO Congratulations. Its time to begin the game.
ECHO Dont worry about weapons, or equipment. You will be
ECHO able to aquire equipment in just a moment.
ECHO.
ECHO.
ECHO Now you have already picked your race, but what about
ECHO a little background history.
ECHO.
ECHO For instance which planet were you born on.
ECHO.
ECHO Where are your currently headed in this life.
ECHO.
ECHO Where has your life taken you thus far.
ECHO.
ECHO What are your dreams, hopes, and goals for the future.
ECHO.
ECHO Do you have a particular affiliation you resonate with.
ECHO.
ECHO Do you have a specific trade, guild, or job you follow.
ECHO.
ECHO We will decide these now, and very soon, you will be
ECHO on your way.
ECHO.
ECHO.
PAUSE
ECHO Lets start with where you were born.
ECHO.
ECHO.
set /P HUPLTBTHBG= "Luminosity, Erithrium, Sprocket, Verderous, Totem, Crest, Vaushan-Roid"
IF '%HUPLTBTHBG%'=='Luminosity' GOTO HUFUTRGOALSBG
IF '%HUPLTBTHBG%'=='Erithrium' GOTO HUFUTRGOALSBG
IF '%HUPLTBTHBG%'=='Sprocket' GOTO HUFUTRGOALSBG
IF '%HUPLTBTHBG%'=='Verderous' GOTO HUFUTRGOALSBG
IF '%HUPLTBTHBG%'=='Totem' GOTO HUFUTRGOALSBG
IF '%HUPLTBTHBG%'=='Crest' GOTO HUFUTRGOALSBG
IF '%HUPLTBTHBG%'=='Vaushan-Roid' GOTO HUFUTRGOALSBG
:HUFUTRGOALSBG
PAUSE
ECHO.
ECHO %CHARNAME% , Your birth planet is now %HUPLTBTHBG%.
ECHO.
ECHO.
PAUSE
ECHO What are your future goals in a few words? You can choose from a pre-generated list,
ECHO or choose to enter your own.
ECHO.
ECHO.
set /p HUGOALSSRTPICK= "PredeterminedList, MakeMyOwn"
IF '%HUGOALSSRTPICK%'=='PredeterminedList' GOTO HUFUTRGOALS1
IF '%HUGOALSSRTPICK%'=='MakeMyOwn' GOTO HUFUTRGOALS2
:HUFUTRGOALS1
ECHO.
ECHO Please pick from the pre-determined list
ECHO.
ECHO.
set /p HUFG= "ToDestroyAllLife, ToCreatePeace, ToDiscoverNewKnowledge, ToProtectAllLife, IJustWantToStealStuff, IWantToBecomeRich"
IF '%HUFG%'=='ToCreatePeace' GOTO HUFGRCD
IF '%HUFG%'=='ToDiscoverNewKnowledge' GOTO HUFGRCD
IF '%HUFG%'=='ToProtectAllLife' GOTO HUFGRCD
IF '%HUFG%'=='IJustWantToStealStuff' GOTO HUFGRCD
IF '%HUFG%'=='IWantToBecomeRich' GOTO HUFGRCD
:HUFUTRGOALS2
ECHO.
ECHO Please Enter your future goals, with NO SPACES, and with A CAPITAL FOR EACH NEW WORD.
set /p HUFG=
PAUSE
GOTO HUFGRCD
:HUFGRCD
ECHO.
ECHO %CHARNAME% , Your Future Goal(s) is,are %HUFG%
ECHO.
PAUSE



I want to add that a few times it had worked and gone to the next section, the :STUPID section, but then it will refuse to work again. Its like, Idk...I just dont get it. Ive tried everything I can think of to fix it or substitute it, etc. Nothing works. It either crashes, acts like I have pause when I dont, or says 'THIS' is not blah blah blah.

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

Re: GOTO wont work anymore? Im so lost

#2 Post by Squashman » 24 Oct 2015 17:22

Please use code tags and please provide all the code you are using.

penpen
Expert
Posts: 1991
Joined: 23 Jun 2013 06:15
Location: Germany

Re: GOTO wont work anymore? Im so lost

#3 Post by penpen » 24 Oct 2015 18:55

This Batch creates a test.bat with 100000 "goto :next":

Code: Select all

@echo off
>"test.bat" (
   echo(@echo off
   echo(setlocal enableExtensions enableDelayedExpansion
   echo(set /A "i=0"
   echo(^<nul set /P "=!i!"
   for /L %%a in (1, 1, 100000) do (
      echo(goto :next
      echo(:next
      echo(set /A "i+=1"
      echo(^<nul set /P "=,!i!"
   )
   echo(endlocal
)
It executes without an issue, at least on my win8.1 and win xp.


penpen

Edit: Now tested: Win xp.

ShadowThief
Expert
Posts: 1160
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: GOTO wont work anymore? Im so lost

#4 Post by ShadowThief » 24 Oct 2015 21:28

Change @echo off to @echo on and see what's getting called right before it breaks. There's a good chance it's something totally unrelated.

trebor68
Posts: 146
Joined: 01 Jul 2011 08:47

Re: GOTO wont work anymore? Im so lost

#5 Post by trebor68 » 25 Oct 2015 05:01

@penpen
Your generated batch file runs in a continuous loop. With "GOTO: next" you jump to the first ever jump label of ":next".

@all users
With a few small changes to the batch file of penpen.
Creates the file: Test60a.bat

Code: Select all

@echo off
>"test60a.bat" (
   echo(@echo off
   echo(setlocal enableExtensions enableDelayedExpansion
   echo(set /A "i=0"
   echo(^<nul set /P "=!i!"
   for /L %%a in (1, 1, 100000) do (
      echo(goto :next%%a
      echo(:next%%a
      set /a "tnum = %%a %% 1000"
      if !tnum!==0 echo(echo ## %%a
      echo(set /A "i+=1"
      echo(^<nul set /P "=,!i!"
   )
   echo(endlocal
)



This code indicates that the program will continue being processed, even if not a condition has been met.

Code: Select all

@echo off
setlocal enableExtensions
echo.
set /p var1=Please insert a number with  one digit:
echo.
echo Your input is: %var1%
echo.
if "%var1%"=="1" goto :number159
if "%var1%"=="5" goto :number159
if "%var1%"=="9" goto :number159

echo It has not entered a number 1, 5, or 9.

goto :eof

:number159
echo This text will only displayed if one of the numbers has been 1, 5 or 9 entered.
goto :eof

:otherLabel
rem commands in this block
goto :eof

penpen
Expert
Posts: 1991
Joined: 23 Jun 2013 06:15
Location: Germany

Re: GOTO wont work anymore? Im so lost

#6 Post by penpen » 25 Oct 2015 05:52

trebor68 wrote:@penpen
Your generated batch file runs in a continuous loop. With "GOTO: next" you jump to the first ever jump label of ":next".
No, you are wrong:
The command "goto :next" jumps to the next available ":next"-label (located in the following line).
The above program just counts to 100000, which may take longer than you expect; just change the 100000 to 10 and your output is:

Code: Select all

0,1,2,3,4,5,6,7,8,9,10


Only if the specified label could not be found the search continues from the beginning of the batch file (up to the goto that is executed).


penpen

Edit: Added the last sentence.
Last edited by penpen on 25 Oct 2015 06:16, edited 1 time in total.

penpen
Expert
Posts: 1991
Joined: 23 Jun 2013 06:15
Location: Germany

Re: GOTO wont work anymore? Im so lost

#7 Post by penpen » 25 Oct 2015 06:06

trebor68 wrote:This code indicates that the program will continue being processed, even if not a condition has been met.
It took me some time to find out why you have posted this example; i guess it is because of that:

Code: Select all

ECHO Lets start with where you were born.
ECHO.
ECHO.
set /P HUPLTBTHBG= "Luminosity, Erithrium, Sprocket, Verderous, Totem, Crest, Vaushan-Roid"
IF '%HUPLTBTHBG%'=='Luminosity' GOTO HUFUTRGOALSBG
IF '%HUPLTBTHBG%'=='Erithrium' GOTO HUFUTRGOALSBG
IF '%HUPLTBTHBG%'=='Sprocket' GOTO HUFUTRGOALSBG
IF '%HUPLTBTHBG%'=='Verderous' GOTO HUFUTRGOALSBG
IF '%HUPLTBTHBG%'=='Totem' GOTO HUFUTRGOALSBG
IF '%HUPLTBTHBG%'=='Crest' GOTO HUFUTRGOALSBG
IF '%HUPLTBTHBG%'=='Vaushan-Roid' GOTO HUFUTRGOALSBG
:HUFUTRGOALSBG
PAUSE
ECHO.
ECHO %CHARNAME% , Your birth planet is now %HUPLTBTHBG%.
Good catch, that's probably the cause of Orion's issue:
I have missed that part - i only looked at the part marked in red.


penpen

Orion
Posts: 6
Joined: 22 Aug 2015 18:39

Re: GOTO wont work anymore? Im so lost

#8 Post by Orion » 25 Oct 2015 21:03

wait so what is my problem? I dont understand what you guys are getting at?

ShadowThief
Expert
Posts: 1160
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: GOTO wont work anymore? Im so lost

#9 Post by ShadowThief » 25 Oct 2015 21:10

We're just speculating at this point, frankly. Without the entire code, it's really hard to tell.

Orion
Posts: 6
Joined: 22 Aug 2015 18:39

Re: GOTO wont work anymore? Im so lost

#10 Post by Orion » 26 Oct 2015 00:58

I will post the entire code, but man, its HUGE, at least imho, and its partially unfinished. I will do my best to make it understandable.

ShadowThief
Expert
Posts: 1160
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: GOTO wont work anymore? Im so lost

#11 Post by ShadowThief » 26 Oct 2015 02:24

I mean you can upload the file to Dropbox or something. Or get the code as small as possible while still having the issue.

trebor68
Posts: 146
Joined: 01 Jul 2011 08:47

Re: GOTO wont work anymore? Im so lost

#12 Post by trebor68 » 26 Oct 2015 04:15

The values that are available in an IF construct to enclose with double quotes. But you have used single quotes.

If all conditions are not met, then you should either an error message (such as "The birth planet is unknown.") Issued or to jump back to the beginning of the input, or both.

Code: Select all

@echo off
ECHO Lets start with where you were born.
ECHO.
ECHO.
:labelNum1
ECHO Luminosity, Erithrium, Sprocket, Verderous, Totem, Crest, Vaushan-Roid
set /P "HUPLTBTHBG= Input birth planet: "
IF "%HUPLTBTHBG%"=="Luminosity" GOTO HUFUTRGOALSBG
IF "%HUPLTBTHBG%"=="Erithrium" GOTO HUFUTRGOALSBG
IF "%HUPLTBTHBG%"=="Sprocket" GOTO HUFUTRGOALSBG
IF "%HUPLTBTHBG%"=="Verderous" GOTO HUFUTRGOALSBG
IF "%HUPLTBTHBG%"=="Totem" GOTO HUFUTRGOALSBG
IF "%HUPLTBTHBG%"=="Crest" GOTO HUFUTRGOALSBG
IF "%HUPLTBTHBG%"=="Vaushan-Roid" GOTO HUFUTRGOALSBG
ECHO.
ECHO The birth planet is unknow.
goto :labelNum1

:HUFUTRGOALSBG
ECHO.
PAUSE
ECHO.
ECHO %CHARNAME% , Your birth planet is now %HUPLTBTHBG%.



The IF command is case sensitive. In the following code I have adapted this part, so that when the input is not case sensitive.

Code: Select all

@echo off
ECHO Lets start with where you were born.
ECHO.
ECHO.
:labelNum1
ECHO Luminosity, Erithrium, Sprocket, Verderous, Totem, Crest, Vaushan-Roid
set /P "HUPLTBTHBG= Input birth planet: "
IF /I "%HUPLTBTHBG%"=="Luminosity" (set HUPLTBTHBG=Luminosity) & GOTO HUFUTRGOALSBG
IF /I "%HUPLTBTHBG%"=="Erithrium" (set HUPLTBTHBG=Erithrium) & GOTO HUFUTRGOALSBG
IF /I "%HUPLTBTHBG%"=="Sprocket" (set HUPLTBTHBG=Sprocket) & GOTO HUFUTRGOALSBG
IF /I "%HUPLTBTHBG%"=="Verderous" (set HUPLTBTHBG=Verderous) & GOTO HUFUTRGOALSBG
IF /I "%HUPLTBTHBG%"=="Totem" (set HUPLTBTHBG=Totem) & GOTO HUFUTRGOALSBG
IF /I "%HUPLTBTHBG%"=="Crest" (set HUPLTBTHBG=Crest) & GOTO HUFUTRGOALSBG
IF /I "%HUPLTBTHBG%"=="Vaushan-Roid" (set HUPLTBTHBG=Vaushan-Roid) & GOTO HUFUTRGOALSBG
ECHO.
ECHO The birth planet is unknow.
goto :labelNum1

:HUFUTRGOALSBG
ECHO.
PAUSE
ECHO.
ECHO %CHARNAME% , Your birth planet is now %HUPLTBTHBG%.

Post Reply