Event order in ct.js
September 28, 2020
Event order in ct.js
These events are always executed in the following order:
- Core ct.js library runs;
- Modules get initialized;
- Custom scripts added at project settings are executed;
- room's
oncreateevent is called, which is emitted when a user starts a game or navigates to a new room; oncreateis applied for each copy;- then the main game loop starts:
onstepevent is emitted for all the copies in the room;onstepevent for current room is called;ondestroyis called for all the copies marked to bekilled;- all the copies are reordered then;
ondrawis called for all the copies;ondrawis called for a room;- input events are cleared. Waiting for a new game loop iteration.
- When a user moves to a new room, an
onleaveevent is called for the latest room.
Call order with mod's injections
At startup:
- Core ct.js library runs.
load.js.- Modules get initialized.
- Custom scripts added at project settings are executed;
resload.jsruns once all the assets have finished loading.start.js— called right before a game is started (no room is created yet).- The first room gets created.
- Room's OnCreate is called.
roomoncreate.js.switch.jsis called.ct.camerais properly positioned.
At room transition:
- Previous room's OnLeave event is called.
roomonleave.js.- New room's OnCreate is called.
- Copies are created here, with all their events and injections.
roomoncreate.jsswitch.jsct.camerais properly positioned.
At each frame:
beforeframe.jsis run in global context.beforestep.jswiththisbeing the current type.- Copies' own OnStep is called.
afterstep.jswiththisbeing the current type.beforeroomstep.jswiththisbeing a current room (can be different fromct.room)- Room's own OnStep is called.
afterroomstep.jswiththisbeing a current room (can be different fromct.room)- Copies get destroyed with their OnDestroy event.
- Camera position is updated
beforedraw.jswiththisbeing the current type.- Copies' own OnDraw is called.
afterdraw.jswiththisbeing the current type.beforeroomdraw.jswiththisbeing a current room (can be different fromct.room)- Room's own OnDraw is called.
afterroomdraw.jswiththisbeing a current room (can be different fromct.room)afterframe.jsis called before moving on to the next frame.
At copy creation:
onbeforecreate.js- Copies' own OnCreate is called.
oncreate.js
At copy deletion:
ondestroy.js- Copy's own OnDestroy event is called.
