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;
- When a user starts a game or navigates to a new room:
- Creation is applied for each copy placed in a room asset;
- room's Room start event is called.
- then the main game loop starts:
- Frame start event is emitted for all the copies in the room;
- Frame start event for current room is called;
- Destruction is called for all the copies marked to be
killed; - all the copies are reordered then;
- Frame end is called for all the copies;
- Frame end is called for a room;
- input events are cleared. Waiting for a new game loop iteration.
- When a user moves to a new room, a Room end event 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.
