I’m trying to make a small city building game. I’ve made it so you click to add a building but how would I make it so you have to have enough money before you can? A keyboard sensor adds one to the property “money”. I’ve got this code in a python controller connected to an always sensor and a message actuator.
the other object is an empty and a cube with a left click, mouse over, and message sensor set to 3. It has an and controller and an add object actuator.
If money=3 and I click on the cube it should add a building but it doesn’t, Why?
I hope this was clear, I’ll post a .blend if you need it.
Thanks in advance.
Don’t use messages. Access your money property in Python, and type “if money > 3:”
before the line to add the building. You could do it without Python too, using an expression controller.
You can link an actuator on the second object to the Python controller of the first object (shift-select both objects in 3D view) and then get the owner of the actuator, and the property of the owner.
O.K. I have an object that has the money property and empties to add the buildings, I would have to link the object with the money property to every empty, wouldn’t I?
Better yet, make your money property an attribute of GameLogic.
#--Init the variable somewhere
GameLogic.money = 0
#--And whenever you need to use it...
gl = GameLogic #Since I don't like to type as much :D
if gl.money > 5:
#Do stuff
It works but since I have money=gl.money=0 at the beginning, every time the script runs it resets to zero. I have solved this with properties but I don’t now how to make it work with gl.money.
gl=GameLogic
money=gl.money=0
cont=gl.getCurrentController()
click=cont.getSensor("click")
over=cont.getSensor("over")
if over.isPositive() and click.isPositive():
money=money+1
print money
click is a left click sensor and over is a mouse over sensor.
how can I get this to work right