Scripting some effects, I run into issue. I just not think about it before, but game engine not have one important feature in the script support. No way to address object that contains currently executing script. This is not needed for events, as scripts in them usually just simple procedures, but effects, items, organs, genes?.. They objects, and it's will be good if their scripts can use reference to his host, right?
Those from you, who have experience with object oriented programming, maybe already recognize what I talk about. Yes - "this" keyword, that exist in all object oriented languages. Unfortunately, MVEL2 scripting language not have native support, or I just can't get it to work. But after some time, I found solution.
Now game engine recognize in scripts two keyword that works right the same way as "this" keyword (tryied to use it itself, but got runtime errors - conflict with native Java code).
From now "its" and "This" (with first capital letter) can be used to get reference to object that contains current script. There small limitation though - you can't access private fields in class, even if know about them (as thechically this will be external call). Only public field and methods accessible.
P.S. In engine already exsisted support for other similar keyword: "self" - reference to the character that contain object with currently executed script. Actively used in organs. Before this point this is been enough...
No comments:
Post a Comment