Page 1 of 1

GOTO wont work anymore? Im so lost

Posted: 24 Oct 2015 16:31
by Orion
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.

Re: GOTO wont work anymore? Im so lost

Posted: 24 Oct 2015 17:22
by Squashman
Please use code tags and please provide all the code you are using.

Re: GOTO wont work anymore? Im so lost

Posted: 24 Oct 2015 18:55
by penpen
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.

Re: GOTO wont work anymore? Im so lost

Posted: 24 Oct 2015 21:28
by ShadowThief
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.

Re: GOTO wont work anymore? Im so lost

Posted: 25 Oct 2015 05:01
by trebor68
@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

Re: GOTO wont work anymore? Im so lost

Posted: 25 Oct 2015 05:52
by penpen
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.

Re: GOTO wont work anymore? Im so lost

Posted: 25 Oct 2015 06:06
by penpen
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

Re: GOTO wont work anymore? Im so lost

Posted: 25 Oct 2015 21:03
by Orion
wait so what is my problem? I dont understand what you guys are getting at?

Re: GOTO wont work anymore? Im so lost

Posted: 25 Oct 2015 21:10
by ShadowThief
We're just speculating at this point, frankly. Without the entire code, it's really hard to tell.

Re: GOTO wont work anymore? Im so lost

Posted: 26 Oct 2015 00:58
by Orion
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.

Re: GOTO wont work anymore? Im so lost

Posted: 26 Oct 2015 02:24
by ShadowThief
I mean you can upload the file to Dropbox or something. Or get the code as small as possible while still having the issue.

Re: GOTO wont work anymore? Im so lost

Posted: 26 Oct 2015 04:15
by trebor68
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%.