Money system?

Hi whats the best way that i could make a money system in my game so when you go th a shop you can buy certain things because you dont have enough and when you spend say £10 on bullets but you only had £9 i want it to stop at £0 and not go to £-1 how do i do these two things…
:slight_smile: :wink:

Thanks in advance

Brave,

That’s something that might be a little hard without python, because they don’t have a type that involves only positive numbers. In python you just use an if branch like:

If amountOfMoney >= priceOfThing:
(tab)amountOfMoney = amountOfMoney - priceOfThing

Heres a quick sketch-up I made, might not be perfect but you can change it for your own uses

  1. On your main object(your character probably) you have an interger or float property (“networth”) that tells you how much money you have, and a float or bool named “havesword” - obviously this will determine if you have the object or not
  2. Use a plane that has bitmap text enabled (“words”) and getOwner for it. This way you can set what text it displays by setting its “text” property (string) If you havent used bitmap text in a game yet google for a tutorial, there are plenty

networth = player.networth
words = blahblah.getOwner #your bitmap text plane object
if networth >= 9:
        player.havesword = 1
        networth == networth - 9
else:
        words.text = "you don't have enough money"

I don’t know if you know how to use python, if you dont you can PM me the blend file and I can help you

Guys, you need no python, just use an Expression contoller.
That way, it will not work unless Money is greater then Price.
Now that i think of it, i should have had the expression as “Money >= Price”(Greater or equal to).

Attachments


I wish I knew more about expressions :frowning: Anyway, I tried that out and it works mostly, but has problem - the price is subtracted twice when you hit the key - when you push down on space it subtracts 10, and subracts another 10 when you release space. I think he should stick with python :]

That happend with me too Anoncompboy :frowning:
What is the problem?

the money still goes under £0 and if you dont have enough it will still subtract the amount ie your money £9 price of thing £10 when you buy it your money £-1 ? and will that python work if yes can you explain a little more plz im not a python wiz…lol