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!

ender_scythe
  • 470
  • 7
  • 16
  • 1
    Ah, the classic [delayed expansion trap](http://stackoverflow.com/questions/30282784/combining-all-mp4s-in-directory-with-ffmpeg/30284028#30284028). Add `setlocal enabledelayedexpansion` to the start of your script and change `%money%` to `!money!`. – SomethingDark Jul 03 '15 at 02:01
  • Please answer using an answer, even if you are going to use a link. – ender_scythe Jul 03 '15 at 02:09
  • Please specify your question, if you mean that it would be: `:LOOP........ set BLAHBLAH............. goto LOOP` it's not – ender_scythe Jul 03 '15 at 02: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. – Ryan Bemrose Jul 03 '15 at 02:27

1 Answers1

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
UnknownOctopus
  • 2,057
  • 1
  • 15
  • 26