This document explain how script works inside the engine.
1. Anatomy of a script call
In this section, we will see a scenario of a script call. At the beginning of the adventure, the hero walks in a zone that sends an
IntroDialog message. Here is what happens in the code.
akagoria.cc), the world is updated with
The position of the hero is updated in the physics engine and the physics engine is updated with a call to
The physics engine detects a collision between the hero and the sensor, and triggers a call to
The listener checks that the requirements for the message are fulfilled, and then call
WorldProcessor::update(), just after the update of the physics engine,
Script::handleDeferedMessages()is called (in
The message that was defered is handled at this time and passed to
A call to the Wren script is prepared with the name of the message, and then
Advendture::onMessage()is called (in
The handler in the script retrieves the callback and, in this case, calls an anonymous function that was registered in
A call to
World::startDialog()is made, this Wren call is foreign (in
world.wren) and actually call
startDialog()function sets the current operation to
Talkand adds a dialog to the world state.
The messages are defered because the message handler could change the physical properties of the hero or characters. Changing the physical properties during
b2World::update() is forbidden, the world is locked. So the message handler is called when
b2World::update() is finished.