0

So, I'm making a game with income (variable) and every turn the money variable goes up, as much as the income variable is for example:

set income=350
set /a "money=money+INCOME"

If I use the normal %VARIABLENAME% to call the variable it doesn't work and the money value stays the same. Please help!

4
  • 1
    Ah, the classic delayed expansion trap. Add setlocal enabledelayedexpansion to the start of your script and change %money% to !money!. Commented Jul 3, 2015 at 2:01
  • Please answer using an answer, even if you are going to use a link. Commented Jul 3, 2015 at 2:09
  • Please specify your question, if you mean that it would be: :LOOP........ set BLAHBLAH............. goto LOOP it's not Commented Jul 3, 2015 at 2:15
  • Are you certain that set /a "money=%money%+%income%" doesn't work? This works correctly on my machine. Unless it's inside the parentheses of a FOR ... DO (...) loop. Then it's the delayed expansion problem. Commented Jul 3, 2015 at 2:27

1 Answer 1

1

Your issue could be caused by delayed expansion.

This alternate script should work for you:

@echo off

set money=20 

set income=30

set /a money+=%income% 

pause
Sign up to request clarification or add additional context in comments.

7 Comments

The /a for setting values is unnecessary!
This solution has nothing to do with delayed expansion.
I'm saying OP's problem was caused by delayed expansion
But you don't say how to solve it; you just remove the circumstances that require it in the first place, which won't address the actual problem.
I included a link about delayed expansion, then offered an alternate solution
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.