Creating a wildcard label

July 8, 2010 at 11:52:13
Specs: Windows 7
I know this is a peculiar question, but here goes....

I'm making a text game that will be constantly saving to "CurrentLevel.txt".

At the start menu, there is an option to lad your last save. The code i used is...

SET /p GAMESTATECODE= <CurrentLevel.txt

This works except, if someone tries to cheat, and accidently changes their code to an invalid one, you get an error and it crashes.

I used someones save code from this forum, except I tweaked it.

The level codes will be the same as the labels.

Is there a way to create a label that will be whatever GAMESTATECODE is? Or send a message if the level code doesn't match any of my labels?

NOTE: I did this to avoid having a huge amount of IF commands as there will be a huge amount of saves.

See More: Creating a wildcard label

Report •

July 8, 2010 at 12:14:55
How about:

    ECHO Cheater! No such level! 
    EXIT /B or whatever

Untested, but I use a similar method using passed arguments:

IF /I "%~1" EQU "new_window" (
    2>NUL GOTO %2
[rest of code]

Insomniac at large

Report •

July 8, 2010 at 12:28:51
Sorry, I didn't quite understand the second part to your answer, but I used the first part and it still crashes if its an incorrect code.

I don't know if that's because i didnt use the second part... or...

Would you mind explaining it?

Report •

July 8, 2010 at 14:26:37
Sorry about that...
The second part was only an example that I use in a batch
that I wrote. Without getting into too much detail (it's a long
script!) I have a need to call the same program, but I pass a
label as an argument:

START "My New Window Title" %0 "new_window" "<label>" 

where <label> is the part of the program I want to run. It
sounded like you had/have a similar situation. That second
part is at or near the beginning of my program, so it gets read
and interpreted early on. The code at that label is almost a
batch program in itself, that performs functions and actions
independently of the main program.

But after thinking about it, my IF statement is testing an
unknown (%1) to a known value (new_window). Your IF
statement will ALWAYS test true, because you are testing an
unknown (%GAMESTATECODE%) to itself
(%GAMESTATECODE%). Since the test will always evaluate as "true", there really isn't a point to have the IF statement at all. At this time, I don't have a quick (or any) answer for you...

Insomniac at large

Report •

Related Solutions

July 8, 2010 at 14:49:28
Haha, okay. Thank you anyways for your help. Ill post around on a few different forums, to see if they can come up with a solution, if it's even possible.

Thanks again.

Report •

July 9, 2010 at 18:48:22
Untested, but I imagine it wouldn't be much more than
findstr /i ":%GAMESTATECODE%" "%~F0" >NUL 2>&1
if errorlevel 1 echo Game state corrupted.&exit /b

Report •

Ask Question