Click here to Skip to main content
15,884,472 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
So my batch file is like a game that has money, Well I want it to subtract if they buy something from the game,
My code is below.

Game.bat
@echo off

set money= 1000

echo money left %money%
echo this is a sample trade
echo 1.) Buy gem ($10)
echo 2.) Buy sword($35)
echo 3.) Buy gun($55)

set /p sbuy= 1, 2, or 3: 

if %sbuy% == 1 goto ttrade1
if %sbuy% == 2 goto ttrade2
if %sbuy% == 3 goto ttrade3

Now at this point I want the %money% to subtract from the options and display the current amount of money left.

If anyone can help with this I would be happy
Posted
Comments
Sergey Alexandrovich Kryukov 9-Nov-13 21:20pm    
Don't you think it would be much more fruitful to do some "real" programming? Batch files are useful when they do something simpler.
—SA

1 solution

To be honest, Sergey is probably right - doing this kind of thing in a batch file is not the easiest way: it's a bit like trying to move house using a Ford Ka. You can do it...but it's going to take some serious effort and you'd be much better off using a Transit instead. :laugh:

But, if you must...

The SET statement normally works with string values, but you can force it to integers by using the "/A" option:
SET /A money=1000

Then, you can do things like:
SET /A money=money-100
But seriously? It's going to be difficult, time consuming and a general PITA to maintain - you would be much better off investing your time in learning a "proper" programming language - even QuickBasic would be easier (and if you only knew how much I dislike basic in all it's varieties, you would know how unlikely I am to use that phrase).

I would suggest trying in C# - it's pretty easy to pick up, and it really will make your task a whole lot easier...
 
Share this answer
 
Comments
Braydon 10-Nov-13 12:07pm    
Thanks you make a good point it helps alot
Braydon 10-Nov-13 12:12pm    
But what is /a
OriginalGriff 10-Nov-13 12:31pm    
It's a parameter:
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/set.mspx?mfr=true

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900