2
$\begingroup$

is it possible to add a game property to an object while the bge is running?

I realize you can access them easily enough, I am not asking about accessing properties just so that's clear.

I'm well aware that you can use a string as a list in the bge like so / which would be perfectly fine in most scenario's(and the same goes for dictionaries.) but I think it'd be more professional if you could physically add properties to objects in real time.

    import bge
    scene = bge.logic.getCurrentScene()
    scene.objects['CentralControl']['L1']=str([(000.000,000.000,000.000),(000.000,000.000,000.001)])
print(scene.objects['CentralControl']['L1'])

postscript: this probably isn't important but i'm using blender v2.78a

$\endgroup$

1 Answer 1

3
$\begingroup$

Yes, that's possible.

Game objects behave like dictionaries, so you can just assign any value to any name (no need for adding a property in the Blender GUI):

scene.some_object["new_property"] = "Hello"

You can even store lists, objects and any other data type in these properties.

$\endgroup$
1
  • $\begingroup$ this is considerably easier than I thought it was going to be >.>. and i've used bge for quite a long time now lmao $\endgroup$
    – Frederick
    Jul 24, 2019 at 6:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .