Thinking out loud -changing bone constraints

step 1

add ragdoll on actor death

Ragdoll = bge.logic.getCurrentScene().addObject('RagdollGroupInstance,own,0)

Armature =  bge.logic.getCurrentScene().addObject(own['ArmCopyOnHiddenLayer',own,0)

for const in Armature.constraints:
    for bones in eval(Ragdoll['RagBones']):
        if bones.name==const.name:
            const.target=bones

but a issue I am having is eval(Ragdoll[‘Ragbones’])
throws a error,

it contains
the string - [‘MCH-forearm.L’,‘MCH-upper_arm.L’,‘MCH-head’,‘MCH-neck’,‘MCH-chest.001’,‘MCH-chest.002’,‘MCH-hips’,‘MCH-forearm.R’]

how do I turn a string into a list?

ok I have -


import bge
import ast


def main():


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


    print('Fire')
    ##add ragdoll on actor death


    Ragdoll = bge.logic.getCurrentScene().addObject('addObb.001',own,0)


    Armature =  bge.logic.getCurrentScene().addObject(own['Armature'],own,0)
    print(Ragdoll['RagBones'])
    x = Ragdoll['RagBones']
    x2 = Ragdoll['RagBones2']
    
    list1 = ast.literal_eval(x)
    list1 = [i.strip() for i in list1]
    list2= ast.literal_eval(x2)
    list2 = [i.strip() for i in list2]
    
    list1 = list1+list2
    print(list1)
    for const in Armature.constraints:
        print(str(const)+" is the name of the constraint")
        for bones in list1:
            print(str(const)+" is checking "+str(bones))
            print(bones)
            if const.name==bones+": Copy Rotation":
                const.target=bones
    for objects in own.childrenRecursive:
        if 'Actor1CameraHook' in objects:
            objects.removeParent()
            cam =bge.logic.getGetCurrentScene().active_carmera
            if cam['Target']==own:
                bge.logic.getGetCurrentScene().active_carmera.suspendDynamics()
                cam['Target']="Empty"
        if 'CamTarget' in objects:
            objects.removeParent()
    own.endObject()          
            
main()



but I am having issues with the constraint names format not matching each other :frowning:

edit: I think it’s because they were added using diff versions, I will clear them all and add them back

eval() is evil.

Because it executes any Python code that is in that string … it could even clean your hard disk ;).

Why is there a string in this property? It does not look like you entered that manually.
Why didn’t you added a list instead? That is what you finally expect.

I stored a property in a object on a hidden layer,
that was a list stored as a string, in the ragdoll
group instance empty,

I dont know how to
access group objects spawned as a instance
from the empty you add them with,
so I just stored them.

I got it working btw, I had100% of the code right and forgot to
play 1 frame of action on the added armature for a while

frustrating.

now it works great
check my thread for team projects wrectified.