Blender 2.77a property bug? (Referencing)

Hi!
I have this python code, connected with always-true sensor:


#I declared PB before, ignore it
for o in own ["PB"]:
    if 'pos' not in o:
        o['pos'] = o.worldPosition

for o in own ["PB"]:
    o.worldPosition = [10,10,10]

for o in own ["PB"]:
    o.worldPosition = o['pos']

Which you would think the final result of the o.worldPosition is o[‘pos’] of the first one right?
BUT, it isnt!
the final o.worldPosition is 10,10,10 and NOT the first o[‘pos’] one!!

can anyone tell me how to bypass this bug?

Yeah seems like you have a problem of references here (you’re not creating a new position, you’re referencing it). So to solve it just use copy(). It’s not a bug by the way.


#I declared PB before, ignore it
for o in own ["PB"]:
    if 'pos' not in o:
        o['pos'] = o.worldPosition.copy()

for o in own ["PB"]:
    o.worldPosition = [10,10,10]

for o in own ["PB"]:
    o.worldPosition = o['pos']

I’ve not tested it, but it should work.

Thanks @elmeunick! I didn’t know bge has referencing, looks like it was disabled on 2.76a which is the engine version I was using 2 days ago