Python Script for this

Hello, I’m trying to make a python script for a simple step but since I never learned Python language there a lot of sintaxes that I don’t know. I have a brick for keyboard (press arrow down) and conntected to a script. What I want it to do is: if the object location is the [x,y,z] then set worldposition = [newx, newy, newz]. No elses needed. Basically I want to make a selection menu with the arrows (go down or up to select and then press enter to chose the correct one) I don’t know if I’m making the things complicated and there is other path for doing that. Thank you.

Display closest x movement choices?

kinda like final fantasy tactics?

and then choose a tile and walk there?

I can help you, but I need a better description of behavior.


Measuring an exact location is no good idea. You need to take the precision of numbers into account. This easily make a location not match a given one. If you really want to be dependent on location it is better to think of areas (is object within an area).

This is a bit more complex. Lets analyse what we need:


  • a selected object


  • select an selectable object
  • deselect an selectable object
  • find a selectable object above/below the selected object
  • get the selected object
  • chose the selected object
  • measure up arrow
  • measure down arrow
  • measure enter

this is quite a lot. Your question relates to “find a selectable object above/below the selected object”. So I discuss this a little deeper.

Find next object
According to your request you want to order the selectable objects by position. To be more specific the order should be top-down.
You can sort the selectable objects by Y-Axis (if that is the top-down axis).

demo code on sorting (and filtering)

import bge

def showSort():
    scene = bge.logic.getCurrentScene()
    allObjects = scene.objects
    print("all     ", allObjects)

    selectableObjects = filterByPropertyName(allObjects, "selectable")
    print("filtered", selectableObjects)

    sortedObjects = sortByY(selectableObjects)
    print("sorted  ",sortedObjects)

def filterByPropertyName(objects, propertyName):
    return [object for object in objects
            if propertyName in object]
def sortByY(objects):
    return sorted(objects, 
                    key=lambda object:
                        object.worldPosition.y # here the y axis gets read               
                  , reverse=True)

Ensure you have a few objects with property “selectable”.
Run this code from any game object via python controller Module mode “demo.showSort”

Your next step will be to navigate on the list. To do that you need to implement at least

  • get selected object

Any idea how to do that?

Wow, never thought it would be so tricky. Yes, I wanted a list like in FF mentioned above but for a menu with only 3 items. In my idea I was wondering if it would be possible to get by a simple if process (if it’s in position x and press down go to position y, if press up go to position z) and so on. Something around that. Then I had the process of ‘Enter’ to get the selected position that I was expecting to do with a message brick in a empty for ex and then message -> scene.

Maybe it’s impossible to achieve like that I don’t know, my biggest problem is to know the sintaxes for Python scripts.

Thank you.

Just encode the options in each tile.

so each tile has a table of vectors that is tile adjacent to that tile,

selecting a vector then moves the player at a fixed rate and animates his walk cycle?

Comparing coordinates is simple. You basically compare the z component of the object’s position.

I wanted to show you that this is only a small part of what you really want to get. The proposed solution is for any number of items.

Three items is where your really should think about such a programmatic solution. With one or two items you can hard-code the behavior with logic bricks. Three and more are still possible but result in a lot of work.