Some background: I have a loaded scene named HUD and I also have a list weaponList. The list has 9 items, and if I have a certain gun, there will be a string of that gun’s name in that list in a specific slot, and if I don’t have a gun, there will be None in that slot.
In my HUD scene I have 9 icons, each representing a weapon. The icon array is visible only when I change my weapon, and visible only like for 3 seconds. All of that works perfectly fine.
What I try to do now is make it not show all 9 icon objects in the HUD scene if I don’t have all the weapons. I can easily do that with setting object.color[3] = 0 to the icons that of which weapons I don’t have, but I seem to need a small wayaround:
The list weaponList looks like this: weaponList = [“Blaster”, “MachineGun”…]
The icon objects’ names in the HUD scene are: “IconBlaster”, “IconMachineGun”…
If the “Icon” wouldn’t be in the names of these objects, then the code would be simple:
for object in HUD:
if not object.name in weaponList:
object.color[3] = 0
But the thing is that it will apply to ALL of my objects in the HUD scene, including Health etc… That’s why I have an “Icon” prefix to the icon objects.
So I need to do something similar to this:
for object in HUD:
if "Icon" in object.name:
if not #object.name without the "Icon" prefix# in weaponList:
object.color[3] = 0
What’s a convenient way in Python to write the #object.name without the “Icon” prefix#?