Wednesday, February 3, 2010

Work Progress - Feb 1 - Feb 6

* Possible to enter values to the textfields in the PStatmentMethods visualized in the middle JPnlScriptlet window. The values are saved appropriately in the underlying statement tree data structure.

* The statements in the statement tree can really be executed (at least the OnBegin which works once the simulation begins.)

* Towards a demonstration
  • For a PObject to be creatable by Menu action, one needs to provide a constructor with two parameters - name and description.
* Study on PEvent
  • Examples of how to trigger PEvent other than OnBegin are not there in the SkateBoarder code.
  • One can simply treat the Begin Event as the only statement tree associated with an object on the render view, just like what we have in Scratch.
  • 8:05 AM me: PEvent?
    8:06 AM cmercenary: Yep.
    That's the one.
    Now, you can also make your own PEvents. For instance:
    Let's suppose you want to give the user a way to have code be run when something happens in the simulation.
    8:07 AM For instance, the skateboarder tips over.
    What you would do would be:
    1) Create a new PEvent. Give it a name, etc. You can see SkateBoarder.java:59 for an example of this.
    2) Annotate it with the @AutomatableEvent annotation, to signal to the core that you want the user to be able to use this event.
    8:08 AM 3) Call the event's Invoke method when the conditions of the event are satisfied--in this case, when you detect the boarder has tipped over.
    Follow?
    8:10 AM me: Get (1) and (2). But for (3), what do you mean by "detecting the border has tipped over"?
    8:11 AM cmercenary: Well, the simulation runs and moves the boarder a little bit forward every few ms, right?
    me: Yes. So it's the responsibility of the programmer, not the user, to tell when the PEvent (in this case, tippedover) should be triggered, right?
    8:12 AM cmercenary: Correct.
    In fact, think about it like this:
    The programmer sends messages to the user's code via PEvent.
    8:13 AM The user sends messages to the programmer's code via PMethod (or, more specifically, PStatementMethod)..
    8:14 AM me: You mention separate statement tree roots are associated with different events. So the scriptlet window has to know which event it is currently editing, so as to display the correct statement tree for editing, correct?
    cmercenary: Exactly.

No comments:

Post a Comment