I'm working on a batch script to generate text descriptions of characters for an RPG. For some reason, it's hard crashing at this line:
if "%sex%" equ "male" (set title=Prince)
I've tried every other formatting of the if statement I know of, including the much simpler:
if %sex%==male set title=Prince
I know it's this line causing the issue as I've used pause/echo markers to find exactly where the crash occurs, and it's the moment it gets to this statement (other options for %sex% are irrelevant as for testing purposes it's hard coded to be male). I'd post the whole code here, but currently it's sitting at 5,537 lines (I know I really shouldn't do procedural generation in batch but this is all I know...)
The script has a few bits at the start which might make things a little diffrent from normal. Specificly it starts with:
chcp 65001@echo offsetlocal ENABLEDELAYEDEXPANSIONmode con cols=150 lines=50CD %~dp0/data
As far as I know, all chcp 65001 should do is force the program to accept Unicode characters. Which it has to for the purposes of creating certain names. It also has to work out of that data directory due to pulling data from around 80 files.
I'm not sure how those could effect a simple if statement that's checking one variable and setting another based on it. Especially when I have hundreds of those statements in the script and the others all work fine.
Running it from CMD as Squashman sugested outputs the following:
C:\Users\Meep\Desktop\Steel Tech Autobigraphy\data>if Ros EQU Ros set parentnames=Your parents were King Camden and Queen Reece of Wigord, a small monarchy making up one of the many nations on Ros. C:\Users\Meep\Desktop\Steel Tech Autobigraphy\data>goto FMRoyTitleSelect C:\Users\Meep\Desktop\Steel Tech Autobigraphy\data>if Ros EQU Bel goto titleskip C:\Users\Meep\Desktop\Steel Tech Autobigraphy\data>if Ros EQU Avar goto titleskip C:\Users\Meep\Desktop\Steel Tech Autobigraphy\data>if Ros EQU Tavros Station goto titleskip C:\Users\Meep\Desktop\Steel Tech Autobigraphy\data>if Ros EQU Ros if male == male set title=Prince C:\Users\Meep\Desktop\Steel Tech Autobigraphy\data>if Ros EQU Ros if male == female set title=Princess set was unexpected at this time.
At request of Squashman, here's the full if statment table, and the code that happens next.
:FMRoyTitleSelectif %homeworld% equ Bel goto titleskipif %homeworld% equ Avar goto titleskipif %homeworld% equ Tavros Station goto titleskipif %homeworld% equ Ros if %sex%==male set title=Princeif %homeworld% equ Ros if %sex%==female set title=Princessif %homeworld% equ Pernia if %sex%==male set title=Lordif %homeworld% equ Pernia if %sex%==female set title=Ladyif %homeworld% equ Temian if %sex%==male set title=Heirif %homeworld% equ Temian if %sex%==female set title=Heiressif %homeworld% equ Fables if %sex%==male set title=Thaneif %homeworld% equ Fables if %sex%==female set title=Thaneif %homeworld% equ Kelezza if %sex%==male set title=Masterif %homeworld% equ Kelezza if %sex%==female set title=Mistressset boop=%title% %firstname%set firstname=%boop%echo title selectedpause
Any suggestions?
Here is the shortest possible code snippit that produces the error:
chcp 65001@echo offtitle test systemsetlocal enabledelayedexpansion::------- setting varriables staticly for test purposes -----------set sex=maleset homeworld=Rosset kingdom=Somewhereiaset dad=Dadset mom=Mom::-------- vvv code in question vvv --------:FMRoyAif %homeworld% equ Ros goto FMRoyA1if %homeworld% equ Pernia goto FMRoyA2if %homeworld% equ Temian goto FMRoyA3if %homeworld% equ Fables goto FMRoyA4if %homeworld% equ Bel goto FMRoyA5if %homeworld% equ Avar goto FMRoyA6if %homeworld% equ Kelezza goto FMRoyA7if %homeworld% equ Tavros Station goto FMRoyA8:FMRoyA1if %homeworld% equ Ros set parentnames=Your parents were King %dad% and Queen %mom% of %kingdom%, a small monarchy making up one of the many nations on Ros.goto FMRoyTitleSelect:FMRoyA2set /a choice=(%RANDOM% %% 100)+1if %choice% leq 50 set parentnames=Your parents were Lord Governer %dad% and %mom% of %kingdom%, the ruling family of Pernia.if %choice% gtr 50 set parentnames=Your parents were Lord Governer %mom% and %dad% of %kingdom%, the ruling family of Pernia.goto FMRoyTitleSelect:FMRoyA3set /a choice=(%RANDOM% %% 100)+1if %choice% leq 50 set parentnames=Your parents were Grand Minister %dad% and %mom% of %kingdom%, one of the many nations of Temian.if %choice% gtr 50 set parentnames=Your parents were Grand Minister %mom% and %dad% of %kingdom%, one of the many nations of Temian.goto FMRoyTitleSelect:FMRoyA4set /a choice=(%RANDOM% %% 100)+1if %choice% leq 50 set parentnames=Your parents were High King %dad% of Fables, and %dp2% concubine %mom%.if %choice% gtr 50 set parentnames=Your parents were High Queen %mom% of Fables, and %mp2% concubine %dad%.goto FMRoyTitleSelect:FMRoyA5set /a choice=(%RANDOM% %% 100)+1if %choice% leq 50 set parentnames=Your parents were President %dad% %lastname% of Bel, and %dp2% wife %mom%.if %choice% gtr 50 set parentnames=Your parents were President %mom% %lastname% of Bel, and %mp1% husband %dad%.goto FMRoyFin:FMRoyA6set /a choice=(%RANDOM% %% 100)+1if %choice% leq 50 set parentnames=Your parents were Prime Minister %dad% of Avar, and %dp2% concubine %mom%.if %choice% gtr 50 set parentnames=Your parents were Prime Minister %mom% of Avar, and %mp1% concubine %dad%.goto FMRoyFin:FMRoyA7set /a choice=(%RANDOM% %% 100)+1if %choice% leq 50 set parentnames=Your parents were Lord Governer %dad% of Kelezza, and %dp2% concubine %mom%.if %choice% gtr 50 set parentnames=Your parents were Lord Governer %mom% of Kelezza, and %mp2% concubine %dad%.goto FMRoyTitleSelect:FMRoyA8set /a choice=(%RANDOM% %% 100)+1if %choice% leq 33 set parentnames=You are the child of Captain Steel, and your mother %mom%.if %choice% gtr 33 if %choice% leq 66 set parentnames=You are the child of Captain Steel, and your fauther %dad%.if %choice% gtr 66 if %choice% leq 98 set parentnames=You are the clone of Captain Steele, and were raised mostly by their dear friend %mom%.set steeleflag=1goto FMRoyFin:FMRoyTitleSelectif %homeworld% equ Bel goto titleskipif %homeworld% equ Avar goto titleskipif %homeworld% equ Tavros Station goto titleskipif %homeworld% equ Ros if %sex%==male set title=Princeif %homeworld% equ Ros if %sex%==female set title=Princessif %homeworld% equ Pernia if %sex%==male set title=Lordif %homeworld% equ Pernia if %sex%==female set title=Ladyif %homeworld% equ Temian if %sex%==male set title=Heirif %homeworld% equ Temian if %sex%==female set title=Heiressif %homeworld% equ Fables if %sex%==male set title=Thaneif %homeworld% equ Fables if %sex%==female set title=Thaneif %homeworld% equ Kelezza if %sex%==male set title=Masterif %homeworld% equ Kelezza if %sex%==female set title=Mistressset boop=%title% %firstname%set firstname=%boop%:titleskip:FMRoyFinif steeleflag=1 goto steelespacialset /a choice=(%RANDOM% %% 8)+1if %choice% equ 1 set parentsatt=Your parents were very distant. blah blah blahif %choice% equ 2 set parentsatt=Your parents were distant. blah blah blahif %choice% equ 3 set parentsatt=Your parents provided you with the normal blah blah blahif %choice% equ 4 set parentsatt=Your parents set asside matters of state blah blah blahif %choice% equ 5 set parentsatt=Your parents made riasing you a priority. blah blah blahif %choice% equ 6 set parentsatt=Your parents waned to care for you, but blah blah blahif %choice% equ 7 set parentsatt=Your parents did their best to raise you, but blah blah blahif %choice% equ 8 set parentsatt=Your parents never wanted to have you. blah blah blahgoto elemntaryschool:steelespacialset parentsatt=blah blah blahgoto elemntaryschool:elemntaryschoolecho %firstname% %parentsname% %parentsatt%pauseexit