samedi 19 juin 2021

Batch script hard crashing durring IF statment

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 off
setlocal ENABLEDELAYEDEXPANSION
mode con cols=150 lines=50
CD %~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.

Any suggestions?

Aucun commentaire:

Enregistrer un commentaire