How to use an If statement with binary file---BATCH

October 20, 2012 at 13:18:21
Specs: Windows 7
I'm making a text based game with BATCH and I'd like to know if it is possible to do something like this:

@echo off
if yoyo.bin=WARRIOR CLASS (
  if oyoy.bin=LEVEL 1 (
    echo YAY! YOU ARE A WARRIOR LEVEL ONE!
    )
)

if yoyo.bin=MAGE CLASS (
  if oyoy.bin=LEVEL 1 (
    echo WHOO-HOO! YOU ARE A MAGE LEVEL ONE!
    )
)

And so on. Thanks in


See More: How to use an If statement with binary file---BATCH

Report •


#1
October 20, 2012 at 13:32:24
Not possible, unless you've got a program that has command line support.

Report •

#2
October 20, 2012 at 13:33:59
So there's no way to read them and set them as a variable either?

Report •

#3
October 20, 2012 at 13:40:48
Using a string or something?

Report •

Related Solutions

#4
October 20, 2012 at 13:46:07
LOL, so you're telling me the content of the file is plain text? If so please specify, don't add the lame .bin extension to make it look like something professional.
To set the content as a variable use this:
@echo off & setlocal enabledelayedexpansion
for /f "delims=" %%a in ('type "oyoy.bin"') do set content=!content!%%a

From then on you can do the comparisons.

Report •

#5
October 20, 2012 at 13:49:51
Oh!

And the reason it's .bin is so people can't just go and change it, not to make it "look proffessional"


Report •

#6
October 20, 2012 at 13:52:50
You're the one asking for help here. Try to understand when you're asking for help you do not say "how to make if statement with binary file" when clearly NOT stating the file's content is plain text. Think a little.

Report •

#7
October 20, 2012 at 13:52:54
Unless they, you know, open it in Notepad.

How To Ask Questions The Smart Way


Report •

#8
October 20, 2012 at 13:53:12
Uh, I entered
@echo off & setlocal enabledelayedexpansion
for /f "delims=" %%a in ('type "str.bin"') do set content=!content!%%a
for /f "delims=" %%a in ('type "int.bin"') do set content=!content!%%a
if int.bin==1 (
	if int.bin==1(
		echo YAY
		pause
		)
)

And it said the syntax was incorrect.

Advise.


Report •

#9
October 20, 2012 at 13:56:48
You're using the same variable both times and you're not even including the variable to see if it's 1.
Also please learn some manners you're getting on my nerves. As razor said, it takes someone with half a brain to figure that out.
Fix:
@echo off & setlocal enabledelayedexpansion
for /f "delims=" %%a in ('type "str.bin"') do set strbin=!strbin!%%a
for /f "delims=" %%j in ('type "int.bin"') do set intbin=!intbin!%%j
if "%intbin%"=="1" (
echo YAY
pause
)
Content of str.bin is %strbin%
Content of int.bin is %intbin%

Report •

#10
October 20, 2012 at 13:58:07
Thank you and I'm sorry.

Report •

#11
October 20, 2012 at 14:01:36
Thank you SOO much, actually :P

Report •

#12
October 21, 2012 at 08:41:45
You might be better off saving a content file as one line with delims i,e,

::example file atributes.bin
wizard,1,18,18,18,18,10

these values would represent class,level,str,etc

then use a

for /f "tokens=" delims=," &&A IN (c:\atributes.bin) DO set Class=%%A && set level=%%B && set /a str=%%C

and so on draw them into variables.

:: mike


Report •


Ask Question