1

I am trying to make a batch game but every time I try to run it get the error Missing operand set was unexpected at this time here is the code:

set /a temp2=(%hp% * %lvl% + %exp% * %exptill% + %wepprice% + %power% * %weppower%)/(%gold% + %pots% * %powergain%)
if not %temp1% equ %temp2% set %temp3%=1
goto home                
Monacraft
  • 6,510
  • 2
  • 17
  • 29
  • The most likely problem (VERY likely) is that one of the variables in the long operation does not exist (or has not been set a value) – Monacraft Oct 09 '13 at 00:21

2 Answers2

2

Since this question is still technically unanswered: take the "%"s out of the equation. You don't need them, and in this case they are doing more harm than good; they cause the variables in question to be expanded to nothing if they are not defined. If you use only the variable names, they will be expanded to '0' if they are not defined.

set /a temp2=(hp*lvl+exp*exptill+wepprice+power*weppower)/(gold+pots*powergain)

When you check the values of temp1 and temp2, make sure they are defined by adding 0 to them before the check (this takes care of cases where the arithmetic fails with a "divide by zero" error):

set /a temp1+=0&set /a temp2+=0

You may also want to make sure that temp3 is defined in the last line as well:

if defined temp3 if not %temp1% equ %temp2% set "%temp3%=1"

This arithmetic style will work for Windows 2000 and later.

Lectrode
  • 412
  • 1
  • 3
  • 13
1

try putting parenthesis around the last set. do any of your vars contain symbols?

cure
  • 2,588
  • 1
  • 17
  • 25