What could be the reason for error message Unexpected Goto in batch file with many string compares? -
here code of batch file:
:add_game_now cls echo add game! echo v victory , d defeat set /p add_game= if %add_game%==v goto add_game_now_v if %add_game%==d goto add_game_now_d :add_game_now_v set /a elo=%elo%+20 if %division%==bronze goto add_game_bronze_v if %division%==silver goto add_game_silver_v if %division%==gold goto add_game_gold_v if %division%==platinum goto add_game_platinum_v if %division%==diamond goto add_game_diamond_v if %division%==master goto add_game_master_v if %division%==challanger goto add_game_challanger_v :add_game_now_d set /a elo=%elo%-15 if %division%==bronze goto add_game_bronze_d if %division%==silver goto add_game_silver_d if %division%==gold goto add_game_gold_d if %division%==platinum goto add_game_platinum_d if %division%==diamond goto add_game_diamond_d if %division%==master goto add_game_master_d if %division%==challanger goto add_game_challanger_d
the problem when @ :add_game_now
, enter v
or d
message unexpected goto
, exits.
what reason error message?
if need entire file can send it.
thanks helping , yes not @ coding.
instead of enumerating these goto target labels can use value of variable within label name:
setlocal enableextensions rem goto :eof terminate batchfile rem works if extensions cmd enabled :add_game_now cls echo add game! echo v victory , d defeat set /p add_game= goto add_game_now_%add_game% goto :eof :add_game_now_v :add_game_now_v set /a elo=%elo%+20 goto add_game_%division%_v goto :eof :add_game_now_d :add_game_now_d set /a elo=%elo%-15 goto add_game_%division%_d goto :eof
make sure these labels exist! otherwise batch crash. variable division
has exist , must have value (like 'bronze').
consider use choice
instead of set /p
. way, can make sure uppercase entries allowed , 'v' or 'd'. not need doubled labels anymore then.
Comments
Post a Comment