In the last article I learned a ton about Pulp and all the wonderful ways it makes developing simple games for the Playdate real easy.
Even for simple games, though, it's tough to make a fun game without a little programming.
That's where PulpScript comes in.
Thus far, I've studied a few games' script files.
Many were easy to interpret.
But there were commands I didn't fully understand.
I hope that reading the official PulpScript Docs fills in all those gaps...and sheds plenty more light on what I can do with this handy API.
Table of Contents
- Woah! This document is nearly three times as long as the Pulp Docs!
- Looks like there is a section on the aspects of the language, then several sections all about the many functions made available by the API
This language has:
- Event Handlers
- Persistant Storage
- Control Flow
- Dates and Times
I've dabbled in all of that!
All game logic must occur inside an event handler.
All variables are globally scoped.
All uninitialized variables have a default value of
Variables can hold a number or a string. Strings must be wrapped in double quotes.
Compound expressions are not supported.
Oh, that explains why I kept seeing overly nested
if...then clauses in all the games: because there's not logical AND or OR in PulpScript!
String comparisons are case-sensitive.
Callbacks and event handlers can be exited early with the done statement
Variables can be persisted across launches using the
Oh, so that's what those keywords were doing!
calltriggers an event for the current tile
emittriggers an event for all tiles that implement that particular event
forloops, but there is a
The built-in functions I recall:
When these functions are called:
- on the game, or once on the game
- on each room, or the current room
- on each tile or the current tile
- on the Player each time they move or collide with a tile
- on an item when the player collides with that tile
The menu-related functions:
I wonder how the cursor is controlled in a Pulp game...especially such that a series of menu items in-game can be selected using any of the buttons on the Playdate.
The functions I now know exist:
Throughout the built-in functions, the
event object may have one or more of the following read-only
members a.k.a. properties:
dx- horizontal direction: -1 (up), 0 (same), 1 (down)
dy- vertical direction: -1 (up), 0 (same), 1 (down)
tx- X coordinate of the target tile relative to the room
ty- Y coordinate of the target tile relative to the room
x- X coordinate of the tile
y- Y coordinate of the tile
tile- name of the current tile
room- name of the current room
px- current player X coordinate
py- current player Y coordinate
aa- absolute angle of the crank
ra- relative angle of the crank (degree difference relative to the previous frame)
frame- number of frames elapsed since game start
ax- accelerometer's X value
ay- accelerometer's Y value
az- accelerometer's Z value
orientation- a string describing the Playdate's current orientation
option- currently selected option's name
game- name of the game
player- name of the player tile
This object can be used to override the default settings through its writable members.
Things that can be changed include:
- Input delays
- Camera settings
- Color of out-of-bounds tiles
- Time delays
- Text interaction and display timings
Lots of great variables for use in tracking time!
Hooray for use of curly braces to interpolate values inside a string!
And very cool that strings can be padded on each side a specific amount.
And putting tiles in a string? Hmm. I'm not sure how I would use that, but cool.
logworks as expected
dumpis a great troubleshooting tactic
saypresents a message...and can be positioned and re-sized!
askis like a
switchstatement where each clause is an
optionand the body of a reaction
- I wonder how
menudiffers in appearance and use than
finis the true game-ending prompt, eh? At least because it emits the
on finish doevent
swapreplaces a tile's artwork with that of another
frameIndexcapture a frame from a tile's animation set
playstarts - optionally interrupting? - a tile's series of animation frames
waitcreates a delay, with exception to the
runloop...? And there's a caveat about preventing player movement? I don't quite understand those parts yet.
shakeis a nice touch!
telllets me manipulate one tile from another
emitdo the same thing, but one for a single tile and the other for any/all applicable tiles
mimicseems interesting, but not sure what a use case is at this moment
listenare great player-input-disabling functions!
actis very interesting: perform some foreshadowing!
drawcan only be called from the Player's
hidemakes it impossible to draw the player. So...like, to simulate a tunnel?
windowdraws a window frame. Cool?
labelplaces text on the room and not in a window or prompt: so for UI elements, perhaps?
cropessentially creates a mask over the room within which drawing can occur
gotomoves the player to a position in a room
soundplays a sound
onceplays a song and stops, optionally doing more things when the song has finished
loopplays a song again and again
stopends the currently playing song
btmadjusts the beat of the song
storesets a value in storage when a game or room is entered or exited
restoresets a value from one in storage
tossdeletes values from storage
randomgenerates a random integer
floorrounds a decimal down to the nearest integer
ceilrounds a decimal up to the nearest integer
roundrounds a decimal to the closest integer
tangentdo geometry things based on a number
radiansconverts a number from degrees to radians
degreesconverts a number from radians to degrees
invertdraws the opposite color and returns the current mode
solididentifies a tile as solid or not
typeidentifies a tile's type
ididentifies a tile from its position or name
nameidentifies a tile from its position or id
Lots of feelings
- So many event functions!
- So many event object members!
- So many other functions!
- Tons of knowledge gaps filled!
- Lots of questions about some of these functions and event handlers!
- Excitement to
logtons of things in tons of event handlers to learn first-hand how all this works!
- Try to find a comprehensive tutorial on building a game in Pulp?
- Start with the list of links on the Pulp help page?
- Or see what's on Youtube?
- Or skip all that and just play around in the editor myself, struggling gleefully the whole time?
It all sounds like it's gonna be a ton of fun...especially now that I'm more familiar with PulpScript and how Tiles work.
Oldest comments (0)