| View previous topic :: View next topic |
| Author |
Message |
xDabombx
Joined: 02 Jan 2008 Posts: 20
|
Posted: Wed Jan 23, 2008 2:10 am Post subject: Need some help with shop |
|
|
| ok i have the basic idea for how to code a shop. for instince in my game i make it so when you kill someone you get +5 points(money) and i have a shop that if something costs $10 it would subtract 5 points, but i need help on making it so that you cant buy something you have enough money for, so it dosnt go into the negatives. any help at all would be greatly apreciated |
|
| Back to top |
|
 |
|
|
tkgd2007 50+ Club
Joined: 15 Nov 2007 Posts: 95
|
Posted: Sun Feb 10, 2008 12:37 pm Post subject: Re: Need some help with shop |
|
|
moneyvar is the amount of money you have in your wallet and amount is the amount of money the object you are trying to purchase.
The following code checks to make sure that you won't go into negative money by purchasing something.
| Code: |
if (moneyvar - amount >= 0){
//do something
} |
You could also add an error message saying you don't have enough money
| Code: |
else{
//error message or sound or whatever
} |
|
|
| Back to top |
|
 |
|