Scripting
If you have questions, please ask them in our Discord server and we'll answer them promptly! 😊
Dreamlab scripts are written in TypeScript and all new projects are created from one of our pre-made templates. These templates are setup to work with Dreamlab correctly out of the box, so you don’t need to worry about configuring anything yourself.
Entrypoints
All scripts must implement three entrypoints for client code, server code, and level data. These are client.ts
, server.ts
, and level.ts
respectively.
Note that level.ts is automatically generated by the level editor and cannot be edited by hand.
Client and Server entrypoints must export a single function named init()
that has a single argument, a reference to the current Dreamlab game context.
Although not strictly required, we recommend defining another shared entrypoint that is called by both client and server init()
functions that calls
any common code shared between client and server. A good example of such code would be registering spawnable entities.
All new projects created from our templates already have these entrypoints set up correctly and are fully type-safe.
import type { InitShared } from '@dreamlab.gg/core/sdk'
export const sharedInit: InitShared = async game => {
// ...
}
import type { InitClient } from '@dreamlab.gg/core/sdk'
import { sharedInit } from './shared.ts'
export const init: InitClient = async game => {
await sharedInit(game)
// ...
}
import type { InitServer } from '@dreamlab.gg/core/sdk'
import { sharedInit } from './shared.ts'
export const init: InitServer = async game => {
await sharedInit(game)
// ...
}
Imports
- Always available
@dreamlab.gg/core
@dreamlab.gg/ui
matter-js
pixi.js
react
- esm.sh
- add note about types
Static Assets
- Info about
resolve()
andworld://
ands3://