{"action":"opened","issue":{"url":"https://api.github.com/repos/okamstudio/godot/issues/1293","labels_url":"https://api.github.com/repos/okamstudio/godot/issues/1293/labels{/name}","comments_url":"https://api.github.com/repos/okamstudio/godot/issues/1293/comments","events_url":"https://api.github.com/repos/okamstudio/godot/issues/1293/events","html_url":"https://github.com/okamstudio/godot/issues/1293","id":55105558,"number":1293,"title":"[request] Add class method like __getitem__ and __setitem__ in python","user":{"login":"fy0","id":1579850,"avatar_url":"https://avatars.githubusercontent.com/u/1579850?v=3","gravatar_id":"","url":"https://api.github.com/users/fy0","html_url":"https://github.com/fy0","followers_url":"https://api.github.com/users/fy0/followers","following_url":"https://api.github.com/users/fy0/following{/other_user}","gists_url":"https://api.github.com/users/fy0/gists{/gist_id}","starred_url":"https://api.github.com/users/fy0/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fy0/subscriptions","organizations_url":"https://api.github.com/users/fy0/orgs","repos_url":"https://api.github.com/users/fy0/repos","events_url":"https://api.github.com/users/fy0/events{/privacy}","received_events_url":"https://api.github.com/users/fy0/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-01-22T02:07:46Z","updated_at":"2015-01-22T02:07:46Z","closed_at":null,"body":"Hi, here is a example:\r\n\r\nI wrote a unit attribute class like that:\r\n```\r\nclass UnitAttr:\r\n\tvar spd = 160\r\n\tvar level = 1\t\r\n\tvar hp = 10\r\n\tvar mp = 10\r\n\tvar atk = 5\r\n\tvar buff = {}\r\n```\r\nNow I cast a spell, increase my hp and mp:\r\n```\r\n\thp += 5\r\n\tmp *= 1.1\r\n```\r\nIt works:\r\n```\r\n\tvar buff = { change = {hp=100}, scale = {mp=0.1} }\r\n```\r\n\r\nBut I need write 6 functions:\r\n```\r\nclass UnitAttr:\r\n\tvar level = 1\r\n\tvar spd = 160 setget spd_set, spd_get\r\n\tvar hp = 10  setget hp_set, hp_get\r\n\tvar mp = 10  setget mp_set, mp_get\r\n\tvar atk = 5 setget atk _set, atk _get\r\n\tvar buff = {}\r\n```\r\nAnother way looks better:\r\n```\r\n\tfunc get(key, value):\r\n\t\tret = self[key]\r\n\t\tif key in self.buff.scale:\r\n\t\t\tret *= (1 + self.buff.scale[key])\r\n\t\tif key in self.buff.change:\r\n\t\t\tret += self.buff.change[key]\r\n\t\treturn ret\r\n```\r\nBut still not perfect...So I think It is best to add functions like that:\r\n```\r\n    func _getitem(key):\r\n         pass\r\n    func _setitem(key, value):\r\n         pass\r\n```"}}