Getting monkey-patched properties from visibles

1 view
Skip to first unread message

Ben Christel

unread,
Aug 1, 2011, 8:08:40 PM8/1/11
to Emerson Scripting Language: Users
Hi all,

I'm working on a more ambitious version of my context menu idea from
the beginning of the summer. Essentially, I'm making a GUI that will
display any HTML that the scripter of an entity wishes, along with a
set of buttons for user input. The HTML and button list are stored in
monkey-patched properties of a presence, and are displayed on the GUI
when a user clicks on the presence. This will hopefully make the
creation of custom GUIs for games and apps much easier (no need to
edit graphics/default.em or create a separate .js file for the GUI).

I've hit a snag in trying to get the added properties from a visible
object, though. If I script an entity with:

system.self.HTML = "hello, world!";

and click on it, a callback in my GUI module is executed with the
clicked visible (system._selected) as a parameter. This callback
contains the line:

var HTML = visible.HTML ? visible.HTML : "";

which always sets HTML to "", because visible.HTML isn't defined! I
can, however, get other properties (such as the mesh) from the
visible.

Basically, I seem to be setting the HTML property on one object and
trying to get it from another. How can I get a presence from the
associated visible? (or vice versa—I'm not entirely sure which is
necessary here.)

-Ben

behram farrokh thomas mistree

unread,
Aug 1, 2011, 8:48:51 PM8/1/11
to emerso...@googlegroups.com
Ben,
I'd recommend not setting properties on visibles directly, and instead
managing a separate data structure that use visible/presence ids to
index into for shared data. So in your example:

benData[system.self.toString()].HTML = 'hello, world!';

The reason for structuring things this way is a couple fold:
1) It avoids some of the problems you've encountered distinguishing
between presences and visibles.
2) Even though you have two visible objects pointing to the same
visible, currently, they're actually two separate javascript objects:
operations on one will not directly affect the other. This is sort of
ugly, and we could revisit it if you think it's adequately
irritating/broken/frustrating.

-Behram

Reply all
Reply to author
Forward
0 new messages