Please help confirm my doubt

Hi guys,

I’m just learning python and I think it’s great, I was a little concerned about the white space style coming from c++ but now I can understand, and it forces at least coding consistency with the coder.

Anyway, with the game I wanted to ask

  1. you click on an object, then you add a python controller.
  2. then in the python script you do cont.own

Which controls that one object you clicked on.

But what is you want to control other objects in that one python script? How do you reference other objects in the scene?
thanks in advance.

Coming from python to c++ I thought that “{ }” are dumb. Change is hard to accept :slight_smile:

You can also have each object have a script that stores/registers them globally in a dict.

You can use

scene = bge.logic.getCurrentScene()
obj = scene.objects

a = obj[“egg”] #egg in scenr
b = obj[“spoon”] #spoon in scene

Brilliant that worked:

import bge
from bge import logic

def main():

    cont = bge.logic.getCurrentController()
    player = cont.owner

    # get the scene
    scene = logic.getCurrentScene()

    # get an object named 'Sphere' or whatever the object is called
    object = scene.objects["Sphere"]


All I did was make sure the objects are set to dynamic, using the following tutorial

if 'listOStuff' not in own:
    listOfThings =[]

    for objects in bge.logic.getCurrentScene().objects:
       if 'Tag' in objects:


store a list of objects with a property

@BluePrintRandom Oh I see, that way I can have multiple objects with the same property and just call ‘own’ instead of each object individually right?

And I set the property in the add property button on the left hand side?

Sorry, I’m new to python and BGE? So asking dumb questions.

yeah, you can use 1 object, to manage the whole list of objects :smiley:

Wow thanks for that, I’ve downloaded the pdf and plan to read it sometime.

Just remember I’ve never done any python programming at all really, so this is brand new and I’m just wrapping my head around how the logic works in bge.

Why do you need “player” in the is snippet

I was using a youtube video and was just copying the code and changing variables to see what they affected. Yes you’re right proper naming conventions are important.

In regards to script vs module, I totally understand. As I see it a module is sort of like a class, much like a java class where you can call the properties direct. However, this abstraction is quite confusing for newbies especially used to functional programming, so until I get comfortable with python I won’t be using modules any time soon. :wink:

At least do not call your code “main”. This does not express what it is supposed to do.

I’m not quite sure how main works with python. I know in c++ we always define int main() as the entry point, so I just assumed this is how it works in python and bge. It’s also a curious point to make as the default game_logic template has def main(). So why would they include def main() if it was bad practice? Very odd.

Thanks in advance for clarifying my questions. I’m sure I’ll have more at some point.