First Jecs project
Now that you have installed Jecs, you can create your World.
luau
local jecs = require(path/to/jecs)
local world = jecs.World.new()
typescript
import { World } from "@rbxts/jecs"
const world = new World()
Let's create a couple components.
luau
local jecs = require(path/to/jecs)
local world = jecs.World.new()
local Position = world:component()
local Velocity = world:component()
typescript
import { World } from "@rbxts/jecs"
const world = new World()
const Position = world.component()
const Velocity = world.component()
Systems can be as simple as a query in a function or a more contextualized construct. Let's make a system that moves an entity and decelerates over time.
luau
local jecs = require(path/to/jecs)
local world = jecs.World.new()
local Position = world:component()
local Velocity = world:component()
for id, position, velocity in world:query(Position, Velocity) do
world:set(id, Position, position + velocity)
world:set(id, Velocity, velocity * 0.9)
end
typescript
import { World } from "@rbxts/jecs"
const world = new World()
const Position = world.component()
const Velocity = world.component()
for (const [id, position, velocity] of world.query(Position, Velocity)) {
world.set(id, Position, position.add(velocity))
world.set(id, Velocity, velocity.mul(0.9))
}
Where To Get Help
If you are encountering problems, there are resources for you to get help:
- Roblox OSS Discord server has a #jecs thread under the #projects channel
- Open an issue if you run into bugs or have feature requests
- Dive into the nitty gritty in the thesis paper