Passing values between behaviors, etc

10 views
Skip to first unread message

Aaron Drake

unread,
Aug 11, 2010, 6:58:47 PM8/11/10
to Blast Mojo
Is there a way to pass data between behaviors or commands? In
particular, if data is produced via a command, what is the best way to
make that data accessible to another command, or another invocation of
the same command.

In other words, does mojo have an internal buffer for "global" values.
Is that one of the purposes of mojo.Model?

Steven Luscher

unread,
Aug 11, 2010, 7:29:13 PM8/11/10
to blast...@googlegroups.com
Hi Aaron,

It's usually best to broadcast and observe Mojo messages!

In a controller:

this.addObserver(mojo.Messaging.getTopic(“systemStatus”), “onPublish”, “ChangeSystemStatus”);

…and in your behavior/command:

mojo.Messaging.publish("systemStatus", 'theSystemIsDown');

The behavior aliased to "ChangeSystemStatus" will be called whenever it hears the message "systemStatus" being published.

If you're doing something more like trying to track a player's score onscreen, use models.

In your controller:

this.addObserver(mojo.Model.getReference("score"), "onNotify", "AnimateScore");

…and in your score-augmenting behavior:

mojo.Model.set("score", 123);

The behavior aliased to "AnimateScore" will be invoked whenever the "score" model is updated!

In both cases, the message itself, and the contents of the model, will be available to the invoked command/behavior through the handy requestObj.

Cheers,
Steven…
Reply all
Reply to author
Forward
0 new messages