-
Notifications
You must be signed in to change notification settings - Fork 4
怎样判断cell的entity的类别 ?
ilvxna edited this page Aug 3, 2018
·
4 revisions
问: 比如我要写个回调
def call(e):
if(e是Account):
e.x=10
但是className Entity类并没有 isinstance是要是比较个int还可以但是如果是这种自定类别要怎么写呢 isinstance(e,Account)会报错没有宣告Account变数 所以我要怎么用代码判断e的类别呢?
答:
>>>KBEngine.entities.items()
[(2001, Space object at 0x04516C08.), (2002, Space object at 0x04516D58.), (2003, Space object at 0x04516E00.), (2004, SpawnPoint object at 0x04516EA8.), (2005, Space object at 0x04516F50.), (2006, Space object at 0x0483F038.), (2007, Space object at 0x0483F0E0.)]
>>>KBEngine.entities[2001]
Space object at 0x04516C08.
>>>s=_
>>>s
Space object at 0x04516C08.
>>>import Space
>>>isinstance(s, Space.Space)
True
>>>s.className == "Space"
True
>>>type(s)
<class 'Space.Space'>
>>>type(s) == Space.Space
True