"( was unexpected at this time." What does this mean?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Mazel_09
Posts: 1
Joined: 25 Jun 2022 18:57

"( was unexpected at this time." What does this mean?

#1 Post by Mazel_09 » 25 Jun 2022 19:09

Hi, all.

I'm creating a simple game in batch and need some help. I'm stuck on one part in particular, I keep getting the error "( was unexpected at this time." How would I fix it?

Code:

Code: Select all

:inventory
cls
echo Your inventory:
echo.
if %wood%==0 (
	REM
) else if %wood%==1 (
	echo You have %wood% block of wood.
) else (
	echo You have %wood% blocks of wood.
)
if %woodplanks%==0 (
	REM
) else if %woodplanks%==1 (
	echo You have %woodplanks% wood plank.
) else (
	echo You have %woodplanks% wood planks.
)
if %cobblestone%==0 (
	REM
) else if %cobblestone%==1 (
	echo You have %cobblestone% block of cobblestone.
) else (
	echo You have %cobblestone% blocks of cobblestone.
)
if %dirt%==0 (
	REM
) else if %dirt%==1 (
	echo You have %dirt% block of dirt.
) else (
	echo You have %dirt% blocks of dirt.
)
if %coal%==0 (
	REM
) else if %coal%==1 (
	echo You have %coal% piece of coal.
) else (
	echo You have %coal% pieces of coal.
)
if %iron%==0 (
	REM
) else if %iron%==1 (
	echo You have %iron% block of iron ore.
) else (
	echo You have %iron% blocks of iron ore.
)
if %ironingot%==0 (
	REM
) else if %ironingot%==1 (
	echo You have %ironingot% iron ingot.
) else (
	echo You have %ironingot% iron ingots.
)
if %gold%==0 (
	REM
) else if %gold%==1 (
	echo You have %gold% block of gold ore.
) else (
	echo You have %gold% blocks of gold ore.
)
if %goldingot%==0 (
	REM
) else if %goldingot%==1 (
	echo You have %goldingot% gold ingot.
) else (
	echo You have %goldingot% gold ingots.
)
if %diamomd%==0 (
	REM
) else if %diamomd%==1 (
	echo You have %diamomd% diamond.
) else (
	echo You have %diamomd% diamonds.
)
if %emerald%==0 (
	REM
) else if %emerald%==1 (
	echo You have %emerald% emerald.
) else (
	echo You have %emerald% emeralds.
)
if %rawmutton%==0 (
	REM
) else if %rawmutton%==1 (
	echo You have %rawmutton% piece of raw utton.
) else (
	echo You have %rawmutton% pieces of raw mutton.
)
if %cookedmutton%==0 (
	REM
) else if %cookedmutton%==1 (
	echo You have %cookedmutton% piece of cooked mutton.
) else (
	echo You have %cookedmutton% pieces of cooked mutton.
)
if %rawchicken%==0 (
	REM
) else if %rawchicken%==1 (
	echo You have %rawchicken% piece of raw chicken.
) else (
	echo You have %rawchicken% pieces of raw chicken.
)
if %cookedchicken%==0 (
	REM
) else if %cookedchicken%==1 (
	echo You have %cookedchicken% piece of cooked chicken.
) else (
	echo You have %cookedchicken% pieces of cooked chicken.
)
if %rawsteak%==0 (
	REM
) else if %rawsteak%==1 (
	echo You have %rawsteak% piece of raw steak.
) else (
	echo You have %rawsteak% pieces of raw steak.
)
if %cookedsteak%==0 (
	REM
) else if %cookedsteak%==1 (
	echo You have %cookedsteak% piece of cooked steak.
) else (
	echo You have %cookedsteak% pieces of .
)
if %apple%==0 (
	REM
) else if %apple%==1 (
	echo You have %apple% apple.
) else (
	echo You have %apple% apples.
)
if %carrot%==0 (
	REM
) else if %carrot%==1 (
	echo You have %carrot% carrot.
) else (
	echo You have %carrot% carrots.
)
if %wheat%==0 (
	REM
) else if %wheat%==1 (
	echo You have %wheat% piece of wheat.
) else (
	echo You have %wheat% pieces of wheat.
)
if %potato%==0 (
	REM
) else if %potato%==1 (
	echo You have %potato% potato.
) else (
	echo You have %potato% patato.
)
if %stick%==0 (
	REM
) else if %stick%==1 (
	echo You have %stick% stick.
) else (
	echo You have %stick% sticks.
)
if %woodenpickaxe%==0 (
	REM
) else if %woodenpickaxe%==1 (
	echo You have %woodenpickaxe% wooden pickaxe.
) else (
	echo You have %woodenpickaxe% wooden pickaxes.
)
if %stonepickaxe%==0 (
	REM
) else if %stonepickaxe%==1 (
	echo You have %stonepickaxe% stone pickaxe.
) else (
	echo You have %stonepickaxe% stone pickaxes.
)
if %goldpickaxe%==0 (
	REM
) else if %goldpickaxe%==1 (
	echo You have %goldpickaxe% gold pickaxe.
) else (
	echo You have %goldpickaxe% gold pickaxes.
)
if %ironpickaxe%==0 (
	REM
) else if %ironpickaxe%==1 (
	echo You have %ironpickaxe% iron pickaxe.
) else (
	echo You have %ironpickaxe% iron pickaxes.
)
if %diamondpickaxe%==0 (
	REM
) else if %diamondpickaxe%==1 (
	echo You have %%diamondpickaxe diamond pickaxe.
) else (
	echo You have %diamondpickaxe% diamond pickaxes.
)
if %woodensword%==0 (
	REM
) else if %woodensword%==1 (
	echo You have %woodensword% wooden sword.
) else (
	echo You have %woodensword% wooden swords.
)
if %stonesword%==0 (
	REM
) else if %stonesword%==1 (
	echo You have %stonesword% stone sword.
) else (
	echo You have %stonesword% stone swords.
)
if %ironsword%==0 (
	REM
) else if %ironsword%==1 (
	echo You have %ironsword% iron sword.
) else (
	echo You have %ironsword% iron swords.
)
if %goldensword%==0 (
	REM
) else if %goldensword%==1 (
	echo You have %goldensword% golden sword.
) else (
	echo You have %goldensword% golden swords.
)
if %diamondsword%==0 (
	REM
) else if %diamondsword%==1 (
	echo You have %diamondsword% diamond sword.
) else (
	echo You have %diamondsword% diamond swords.
)
pause>nul
goto world_one
Could I please get some insight as to whats happening?

Thanks in advance.

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: "( was unexpected at this time." What does this mean?

#2 Post by aGerman » 26 Jun 2022 05:42

Guessing: One or more of your variables are not defined (have no value at the time you check them in your IF statements). Could be you didn't assign a value, could also be you have a typo in the variable name.

E.g.

Code: Select all

if %wood%==0 (
If variable wood is not yet defined because you didn't assign a value using SET, this piece of code expands to ...

Code: Select all

if ==0 (
... where ( is unexpected due to the missing comparison operand.

Steffen

Post Reply