String search/comparison of Clist api type

In my fps, when the user switches weapons, I want to update the weapon ammo/etc on my HUD

So I decided the way to do that was to update the child object of my arms rig, but I apparently can’t do any string searches of the data in the list? I attempted to use the GET function, but that does not work with partial matching, which is what I need.


            armsRig = scene.objects["fArmsRig"] #getting the object name
            childList = armsRig.children #If i print childList is has 2 objects, the arm mesh and gun run
            guntype = childList.get("weap") #This doesn't work unless I already know the name
            print("TYPE:",guntype,"ENDTYPE") #If I do the full name it prints it here, else error
            if "weap" in guntype: #even though "weap" is in guntype, doesn't trigger
                print("FoundWEAP")


You can get an element from a CListValue the same way you get an element from a dictionary. Just use:

guntype = childList['weap']

Note that scene.objects is also a CListValue and you accessed the rig in this manner in the first line of your code.

Unfortunately, this does not work.

I know the exact name of the scene I want, but I DO NOT know the exact name of the guntype, I just know that it contains the string “weap”. So your

guntype = childList['weap'] 

does not work unless I add the full name of “weapSpas12Rig”, which I wouldn’t know. Otherwise I get the error “CList[key]: ‘‘weap’’ key not in list”

If I’m interpreting correctly, something like this could work:


for c in childList:
    if c.name[:4] == 'weap':
        # This is the one

Awesome, this works, thanks. Tried something like that that did not work, but I didn’t have the “.name” which didn’t realize I could do, thanks again.

Best use str.startswith