script broken OR applyMovement problem OR spawning game buttons in a column

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?

Yes, I see the problem.

The line below your comment doesn’t work because it doesn’t change anything. Neither does the line below it. applyMovement() is meant to assign perpetual movement that updates per-frame, and since this is a loop, you’re assigning incremental movement all at once. It’s unnecessary, since you can accomplish what you’re trying to accomplish with worldPosition. And as for your worldPosition line, it’s not a command. It’s a variable declaration, with a variable that does nothing.

What you want is more like this:

button_emitter_object.worldPosition.y += 1
scene.addObject(button, "officer button emitter", 100)

Now you’re directly changing the worldPosition of the emitter object, instead of just applying movement to it, which is more meant for physics objects.

source: I’ve made a very similar system for my inventory menu. :smiley:

IT WORKS!!! SOLVED!!!

You are a GOD! I have destroyed the evil applyMovement thing which cannot move my static object and am now using worldPosition! Now I can march my officers onto the field!

I’m new to this blender python thing and I need the support so THANKS!

And as a side note: your post gave me the idea to, temporarily, use applyMovement with dynamic buttons and I had a lot of fun, so thanks for that too.