I've multiple planes acting as sensors(buttons) in my game. I want to keep track on the order in which these buttons were clicked and also the total number of clicks. This information has to be processed to give some output. How can this be done? I think this can be done by adding a game property with all the objects sharing this common property and incrementing the property value on click of the plane. How can we have a single common game property for all the objects?
Properties belong to a single game object. They are not shared by default.
There are several ways to implement the requirements you have.
Here is one:
- a single object handles the clicking -> button controller
- the buttons do nothing regarding the click processing (maybe some feedback animation). Each button provides a meaning (e.g. via name or via property).
The button controller can be an empty as it has no further meaning within the 3D scene other than processing the clicks.
The button controller triggers a Python controller on mouse button and mouse over any sensor. Then a button is sensed the controller identifies the meaning and adds an entry to a button tracker. The button tracker tracks the button clicks. It can be a simple list.
import bge def recordClicks(): if not allSensorsPositive(): return hitObject = getHitObject() meaning = hitObject["meaning"] getTracks().append(meaning) print("clicks are", getTracks()) def allSensorsPositive(): for sensor in bge.logic.getCurrentController().sensors: if not sensor.positive: return False return True def getHitObject(): for sensor in bge.logic.getCurrentController().sensors: try: return sensor.hitObject except AttributeError: pass def getTracks(): tracker = bge.logic.getCurrentController().owner try: return tracker["tracks"] except KeyError: tracks =  tracker["tracks"] = tracks return tracker["tracks"]
The clicks are recorded in property "tracks". It is a list (not view able by show debug properties) containing the clicked objects in the order they are clicked.
The clickable objects should contain a property called "meaning". The best is to filter the mouse over any sensor with property "meaning".
Configure the Python controller with Module mode and "demo.recordClicks".
Unfortunately you did not mention what to do with the tracked clicks. So this example just prints them to console.