How to update values in the __init__ constructor in realtime.

Hi I Hope you are having a good day.

I need to know if there’s a way to update the values in the init constructor on the fly.
e.g.


    GameObjects = scene.objects
    Driver = GameObjects[Driver]
    cube = GameObjects[cube]
                  class a:
                         def __init__(self,cube):
                              self.b = Driver.position - cube.position


Now what happens is the self.b attribute only records the starting position
of the cube and does not continue to recalculate the self.b value as the cubes position changes.
How do I go about making sure the value of self.b updates as the position of the cube updates?

Thanks. Any Help and Solutions will be greatly appreciated.

call update() :wink:

init() is executed when an object of that class gets created. It is not supposed to run again. Typically you define other class methods to perform the “business”.

@Monster Thanks
I would have defined another class method but that method would not have access to the values imported by the init method.

@Monster Thanks
I would have made another class method but that method would not have access to the info imported by the init method

(How do I delete a post)

All object related data need to be stored in “self”.

Your example refers to the module variable “Driver”. This creates a dependency from each single object of the defined class to this module variable. Just now I can’t see an reason to do it that way.

As I have no idea what you want to achieve, it is hard to provide suggestions that match you situation.

@Monster
Problem solved!
Thanks for the Help I really appreciate it