HydroReaver
HydroReaver

Reputation: 3

Batch if not error

I have a problem using if not in batch. I'm creating a little game and I have added an inventory system, to carry things around. Basically, at the moment I have 10 inventory slots, and when I view my inventory I want to only see a slot in the inventory if it has an item in it. By default, I have all the inventory slots set to Empty (I know there is probably a simpler way to do this, if there is please let me know) and this block follows;

:inventory
cls
if not %slotone%==Empty echo %slotone%
if not %slottwo%==Empty echo %slottwo%
if not %slotthree%==Empty echo %slotthree%
if not %slotfour%==Empty echo %slotfour%
if not %slotfive%==Empty echo %slotfive%
if not %slotsix%==Empty echo %slotsix%
if not %slotseven%==Empty echo %slotseven%
if not %sloteight%==Empty echo %sloteight%
if not %slotnine%==Empty echo %slotnine%
if not %slotten%==Empty echo %slotten%
pause
goto %invback%

This returns an error, and I'm not sure why. Any help?

Upvotes: 0

Views: 57

Answers (1)

foxidrive
foxidrive

Reputation: 41287

Here is a case insensitive way of comparing text using if not and /i and which protects against spaces, null strings, and poison characters.

if /i not "%slotone%"=="Empty" echo %slotone%

Upvotes: 1

Related Questions