Scripts
Scripts in the sidebar is a TypeScript editor connected to the game. Write a script, press Run (Ctrl+Enter), and it runs against one game or every game that's playing. There's nothing to install.
What a script can use
A script is the body of an async function, so you can await at the top level, and whatever you return is printed. These four names are always defined:
| Name | What it is |
|---|---|
phantom | The game the script runs on. It's the whole SDK: phantom.aj (Animal Jam, area by area), phantom.flash (the game client) and phantom.packets (its traffic). |
packets | All the packet definitions, plus the protocol's readers and writers. |
console | log, info, warn and error. Output shows up below the editor. |
sleep(ms) | Waits, then carries on. |
const position = await phantom.aj.player.avatar.position();
const room = await phantom.aj.room.current();
console.log('Room:', room?.name, 'at', position);
for (const player of await phantom.aj.room.players.all()) {
console.log(player.userName);
}The editor autocompletes the SDK, the game client's classes and the members you can hook, and flags type errors before you run. It takes a few seconds to load the first time you open the page; the corner says when it's ready.
Listeners keep running
A listener, hook or watcher stays active after the rest of the script has finished. The status shows Listening until you press Stop or close the game.
phantom.aj.chat.onMessage((message) => {
console.log(message.userId, message.text);
});Running on several games
Run on picks one game or Every game playing. With every game, the script runs once per game, each in its own sandbox. A game that starts while it's running is picked up too, and if nothing is playing yet the script waits for one.
Saving
Give the script a name in the bar above the editor and press Save (Ctrl+S). Saved scripts are listed on the left, where you can rename and delete them. They're kept in a file on this computer, not in the window's storage.
The Examples tab has scripts to start from. Opening one makes a new script, so saving it won't overwrite yours.
The game client
phantom.flash is the game client itself. You can read its private members and hook any of its methods. It can do anything the client can, so it can also break things the rest of the SDK avoids.
await phantom.flash.hook(
'avatar.UserCommXtCommManager.onSendMessage',
{ capture: { args: ['myMsg'] } },
(call) => console.log('sending:', call.args.myMsg)
);Careful
A script acts as you, in your game, straight away. Automating play puts your Animal Jam account at risk, and Phantom can't take that risk away.
Next
The game guides are written for plugin authors, but scripts use the same phantom. Skip the parts about the manifest and permissions and the code is the same.