Start
Open a cart, change a number, run it
play.onejs.com runs small carts in the browser. Every one shows you its source and can be forked or opened in Unity.
Carts are written in React and TypeScript against a package called oj.
import { View, Text, mount, useFrame, input } from "oj"
function Game() {
useFrame(() => {
if (input.keyboard.wasKeyPressed("Space")) console.log("jump")
})
return <View><Text>hello</Text></View>
}
mount(<Game />)No build configuration and no root plumbing. mount() already knows where to render.
The shortest way in
- Open a cart: Tinder, for one, and press Edit code. Its code opens beside the running cart.
- Change a number in the code.
- Press Run, the play button above the code.
That needs no account, and nothing you do touches the original. Run builds what is in your tab and plays it; it never saves.
The editor's address names the file you have open, so a reload or a copied link opens on it.
To show a cart or record one, the button beside Run presents it: the code at a size a video can read, the cart beside it, and nothing else. Alt + and Alt − size the code, Alt 1, 2 and 3 change how the screen is split, and Escape comes back. Adding ?present to the editor's address opens it that way.
Keeping what you make
Signing in is what lets you keep something: creating a cart, forking one, and saving your work.
New cart, the pen beside your name, opens the editor on a starter cart that is already running, under a made-up name like sleepy-otter. The pencil beside the name at the top of the editor renames it; the name itself goes to the cart's page. Your typing is kept as you go, where only you see it, and Push makes it live: one commit, built, and what everybody plays if it builds. A push that does not compile still lands: the error comes back with the file and line, and what is live does not move. Discard changes, in the Push window, puts the cart back to what is live.
A new cart is public from the start, and so is its repo: anybody can open its page and play it, read its source and history, fork it and add it to a Unity project. Your profile and the cart's address show it at once; the catalog lists it once you have pushed a change to the starter. Forking a cart gives somebody their own copy of the repo with a new id, and yours is untouched.
The gear on a cart opens its settings. Who can play is the cart's own: Public is listed on OJPlay, Unlisted plays for anybody with the link, Private only for you. Runs says what it plays: a branch, which moves with every push that builds, or a version or commit, which stays put. Source is the repo's, shared by all its carts, and stays public unless you make the repo private: then only you can read, clone or fork it, while its Public and Unlisted carts still play for everybody. Delete there removes only that cart.
Two things worth knowing early
Your cart is the JavaScript, not the engine. Unity and the OneJS runtime are one shared container that every cart on the site runs inside, so a cart is a few kilobytes and starts without a download prompt. It also means what you fork is real source.
Nothing here is thrown away. oj is a subset of OneJS, so everything a cart uses also works in a normal Unity project. When a cart outgrows the browser, opening it in Unity is a git clone and one command.
Work locally
Every cart is a git repository, so you can work on one in your own editor. A new one starts on your machine, with no account:
npx ojplay new "My Cart" # the starter in ./my-cart, a git repository
cd my-cart
npm install
npx ojplay run --watch # the site's container in a local Chrome, swapping in each save
git add -A && git commit -m "First version"
npx ojplay push # the first push puts it on the site, public; it asks you to log in onceA cart already on the site clones by its address plus .git (a public cart needs no login):
npx ojplay list # your carts and their addresses
git clone https://play.onejs.com/@<handle>/<name>.git
cd <name>
npx ojplay init && npm install # types and completions, kept out of git
npx ojplay push # builds on the site, and says so if it did not buildFrom your own machine has the rest: running and testing a cart locally, and what happens when the editor and a push both change it.
More than one cart
A repo can have many carts, each running a branch, a version or a commit, and each with its own audience, plays, scores and comments. A push of any branch but main makes it a cart of its own, Unlisted, and changes nothing anybody plays on the others:
git switch -c bigger-ship
git add -A && git commit -m "A bigger ship"
npx ojplay push # builds bigger-ship and prints its cart's linkThat cart plays at the repo's address plus @ and the branch: /@<handle>/<name>@bigger-ship. Anybody with the link can open it, and nothing lists it until you make it Public. Each push of the branch rebuilds it, and one that does not build leaves the last build that did. Deleting the branch (git push origin --delete bigger-ship) deletes the cart its push made, unless you have changed that cart's settings since. A repo keeps up to 10 branch carts; a branch past that is stored with none. A branch named like a version (1.2.0) or a commit (3f2a91c) is refused, since those follow the @ too.
The repo's History lists its carts, what each runs and how far a branch is ahead of main, then every commit on main. New cart beside a commit makes a cart that stays on it (on its version, when it is one), at /@<handle>/<name>@1.2.0 or @ and the commit. To send everybody to what a branch shows, merge it into main and push, or point a cart at that branch in its settings. Delete this repo, at the bottom of History, takes every cart with it.
Where to go next
| Writing a Cart | The entry point, the frame loop, the manifest |
| Elements and Styling | What you draw with, and the traps in it |
| The Stage | The window your cart gets, and a fixed board inside it |
| Files | Sprites, sounds, fonts and covers |
| Effects | Particles, shaders and per pixel programs |
| Opening in Unity | Cloning a cart into Unity, and working on it from your own machine |
Start with Writing a Cart if you want to make something, or Elements and Styling if you have forked one and want to know what the code in front of you does.