1.

Solve : So im making a game...?

Answer»

Quote

it won't always be positive either.

Because there was an ERROR. Which is what you're testing for.0 means no error. any other values generally means an error. which means that (2000/XP/Vista) programs returning a negative number will be flagged as successful, since they are not greater then zero. so basically, the condition should be:

Code: [Select]if not errorlevel EQU 0 goto :fail

You mean if not .The original code I gave (if errorlevel 1 goto fail) is backwards compatible to old versions of DOS and works over 99% of the time in my experience. But the discussion is correct that it won't work with CMD and programs that return negative errorlevels. But just to correct a few things:
1) CHECKING for errorlevel 1 is fine, because that will return true if the errorlevel is 1 or 2 or 3 or 4, etc. (anything HIGHER than 0).
2) The "correct" way with CMD needs to address ERRORLEVEL as an environment variable, so it needs % around it, like:
Code: [Select]IF %ERRORLEVEL% NEQ 0 goto failQuote from: GURUGARY on February 14, 2009, 09:24:49 PM
The original code I gave (if errorlevel 1 goto fail) is backwards compatible to old versions of DOS and works over 99% of the time in my experience.

exactly. == with ERRORLEVEL will be execute the command if the value is greater then or equal to the value- additionally the GTR then and so forth are not available in pure DOS which kind of precludes their USE in that context.


your correction re Errorlevel as a variable is also 100% accurate as well. Quote from: GuruGary on February 14, 2009, 09:24:49 PM
Code: [Select]IF %ERRORLEVEL% NEQ 0 goto fail

So this is the best way to do it, rite?
thanks again.Yes. Do it that way.


Discussion

No Comment Found