hasattr not working in 2.53? What is this?!

hey guys! anyone know why hasattr(object,property) isn’t workin in 2.53? is there an alternate way of determining if its a specific object? i’m just looking for a property called event so it doesn’t give me an error every millisecond :stuck_out_tongue: thanks!

hasattr is indeed deprecated- you’ll want to use object.has_key(property) now.

Any functions that don’t work in 2.5 but did in 2.49 return a deprecation error in 2.49, and suggest the corresponding alternative, the point of which was to help people get used to not using them so they can transition to 2.5. You can also get a list of functions, including deprecated ones, here.

Im getting a has no attribute ‘has_key’ error when i use that one…

import GameLogic as g
cont = g.getCurrentController()
own = cont.owner
objList = g.getCurrentScene().objects

mouse = cont.sensors["mouse"]
lmb = cont.sensors["lmb"]

obj = mouse.hitObject

if lmb.positive:
	for i in objList:
		if i.has_key("clicked"):
			i["clicked"] = False
			
		elif obj.has_key("clicked"):		
			obj["clicked"] = True
			
			
		
		
	
		


		

Try this:

if 'clicked' in obj:

.get() should solve your problems.

if ‘clicked’ in obj: works perfectly! Thanks!