I’m trying to make a column of buttons for my game!
The idea is that there are some objects: a Menu with a Button and a ButtonEmitter parented to it, and several CharacterButton’s on another layer.
So when the Button is clicked, I want a CharacterButton to spawn at the ButtonEmitters location and then move the ButtonEmitter up a bit and then spawn another CharacterButton. This way I would make a column of CharacterButton’s.
And I pieced together this script to do it:
import GameLogic, time
cont = GameLogic.getCurrentController()
scene = GameLogic.getCurrentScene()
query = "character"
move = [0.0, 0.0, 50.1]
back = [0.0, 0.0, -50.1]
local = False
counter = 0
MouseOverO = cont.sensors["MouseOverO"]
MouseButtonO = cont.sensors["MouseButtonO"]
if MouseOverO.positive and MouseButtonO.positive:
home = scene.objects["march officer button"].position
citynameO = scene.objects["city name"]
cityname = cityname0["Text"]
for character in scene.objects:
if query in character.name and character["player"] is True:
button = character["button link"]
# it's like the line below this comment is not working.
scene.objects["officer button emitter"].applyMovement(move, local)
position = scene.objects["officer button emitter"].worldPosition
scene.addObject(button, "officer button emitter", 100)
counter = counter + 1
for x in range(0,counter):
scene.objects["officer button emitter".applyMovement(back, local)
The first for loop and if statement searches through the objects and if it finds a character then it moves the button emitter and spawns a button. Then for subsequent iterations of the for loop it moves the emitter and spawns a button. After the first for loop has ended the second for loop moves the button emitter back.
But the result is not a column of buttons. Instead it draws a bunch of buttons on top of each other. I suspect the line moving the emitter is wrong, but I can’t figure it out.
Can anyone see the problem?