I was making an inventory for game and I hit a wall, that wall being the wall of “how do you cater for an amount of text that is unknown”. So I got into my bulldozer and this is how I beat it.
Layer 2 (Because I like to go backwards >:D): add a plane > texture as realtime text > leave ‘Text’ property blank > name the plane to ‘Text’
Layer 1: Add an empty and call it ‘control’ or something cool like ‘brad_pitt’ > add an always sensor, python controller and an edit object actuator set to add object > Text.
Now for the juicy code that runs this bulldozer.
cont = GameLogic.getCurrentController() own = cont.getOwner() scene = GameLogic.getCurrentScene() add = cont.getActuator("add") GameLogic.addActiveActuator(add, 1) objects = scene.getObjectList() objects.reverse() pos = own.getPosition() own.setPosition([pos, pos, pos - .5]) objects.Text = pos
This little bit right here
objects = scene.getObjectList() objects.reverse() object = objects
can also be done like this:
objects = scene.getObjectList() object = objects[len(objects) - 1]
Finally add the script to the controller and check it out, or if you lazy download my attached example.
In my example I just set the text the z position of the text object but it has other uses, such as if you wanted to display all the contents in a directory, an inventory (as I used it for) or a load script.
This example is just demonstrating how you can control objects after they have being added by a actuator. You can use this method for controlling baddies that have been spawned.
instanced_text_example.blend (144 KB)