Blocks mode
Programming a game by snapping blocks together in editor 0.4.0, with the code in view. How a blocks project is created, the canvas, the palette, its link to the scene, switching to code and what it does not do yet.
DescribesEditor 0.4.0 For creating without programming
On this page
Blocks mode is the third way to give a game its logic, next to Rules without code and code. You snap blocks together like pieces and, on the side, you see the code they write. It is meant for learning to program.
A project is made with Rules or with Blocks, not both: both of them write the game's script. You choose when you create the project.
Everything below was really done with the published editor 0.4.0, dragging the blocks with the mouse. The screenshots are from that session.
Create a blocks game#
- On Your games, press New game.
- At the top, under How it is programmed, pick Blocks.
- Pick the kind of game, a template and the name, and press Create and open.
With Blocks selected, the dialog changes in three places:
| Where | What changes |
|---|---|
| Kind of game | You can pick Third person, First person, 2D platformer, Top-down, Isometric and Open world. 2D / 3D hybrid is switched off, with the label not with blocks. |
| Players | Local multiplayer is switched off in the dialog, with the label on the Game card, after creating: you turn it on later on the Game card. |
| Template | There are five, all of them made of blocks. |
The dialog itself sums it up: "A blocks game uses a single view and pieces, with no tile maps; the open world also brings its cube terrain. You can switch it to code later, but not back from code to blocks."
The templates#
The descriptions are the ones in the dialog.
| Template | What it brings |
|---|---|
| Blank, with blocks | The floor (or a flat world of cubes, for the open world kind), the player and a goal that already ends the game. To build your game by snapping blocks from scratch. |
| Collect the coins | Collect the eight coins in the yard. You win when none are left. |
| Dodge the blocks | Cross the track to the finish without touching the red blocks. You have three lives and one minute. |
| The key maze | Find the key, open the door and reach the finish. A guard watches a treasure: if he catches you, you go back to the start. |
| Crystals and cubes | A world of cubes: break the crystals with a click and then build with a right click. There is a chest with a prize. |
When you pick an example, the checked kind of game becomes that example's.
The canvas#
The project opens on the Blocks tab, which takes the place of the script tab.
| Area | What it is for |
|---|---|
| Object tabs | One for each thing that can be programmed: the game (Juego), the player (Jugador) and each object in the scene. The number says how many programs it has. |
| Palette | The blocks, by category. A click on a category opens it. |
| Canvas | Where programs are built. At the bottom right are center, zoom in, zoom out and the trash can. |
| This is how it looks in code | The script your blocks write, always up to date. The Explain every line checkbox adds a comment per line. |
| Switch to code | Leaves the blocks and carries on by hand. It is one way only: see below. |
In Simple mode, with the canvas in front, the editor hides Place pieces to give it width. It comes back when you open the scene tab.
Build a program#
A program starts with a block from Events, which says when it runs, and continues with the blocks snapped below it, from top to bottom.
- Open the Jugador tab, the player.
- In the palette, open Events.
- Drag when button jump (Space) is pressed onto the canvas.
- Open Motion and drag jump right below it, until it snaps.
- Open Sound and drag play sound coin below jump.
Every change saves the project and rewrites the script. When you select a block, its lines are highlighted in the code and, below, the editor explains in three parts what that block does, which programming idea it uses (here, sequence: the computer follows the instructions one by one, top to bottom) and how that idea looks in code. It works the other way too: a click on a line selects its block.
Undo and redo are the editor's: Ctrl+Z also works inside the canvas, and each drag is a single step.
The categories#
| Category | What it brings |
|---|---|
| Events | When a program starts: when the game starts, when a button is pressed, on click or right click, when the player touches an object, on every frame, every so many seconds, when falling off the world. On a piece or a character, also when I get a click and when a player touches me; on a piece that is a model, when my animation ends. |
| Motion | Go to a point, move, turn, jump, push with a force, change the speed or the jump height, freeze the player, go back to the start. |
| Looks | Change color, show the sprite (with a pencil to draw it), say something, put on a label, show a message, write on screen, show the score table. On a piece that is a model, also animate me with a clip and stop my animation. |
| Sound | Play one of the sounds the game comes with, a tone, a melody of notes or a noise. If the game has recorded sounds, play recorded sound. |
| Control | Wait, repeat, forever, if… then, if… else, wait until, repeat until, stop this program. |
| Sensing | Questions and measures: touching?, distance to an object, button pressed?, holding the click?, is the player looking at an object?, the player's position, how many are left, seconds of play, difficulty level. |
| Operators | Arithmetic, comparisons, random numbers, and, or, not, and blocks to join and check texts. |
| Variables | Named boxes to keep a number or a text. You make them from the palette and they can be shown on screen. |
| Lists | Several things kept in order: add, delete, change, go through them. |
| Cube world | Only in an open world project: break, place and outline blocks, the quick bar, save and restore the world. |
| Game | Add points, win or lose the game, end it recording the points, create and delete copies of an object, change the view, the camera, the sky or gravity. |
| My blocks | Define a block of your own that gathers several, to use it more than once. |
The palette changes with the open object: Motion shows on the player and on pieces, and not on the game.
The new blocks in 0.4.0#
Editor 0.4.0 adds four blocks, for the models, sprites and sounds you make in the workshop or bring in with the importer. The blocks projects you already had stay the same: they generate exactly the same code.
| Block | Category | When it shows up |
|---|---|---|
| animate me with a clip, once or over and over | Looks | On a piece that is a model. The animation only changes how it looks: it does not move it. |
| stop my animation | Looks | On a piece that is a model. It stands still again. |
| when my animation ends | Events | On a piece that is a model, when a clip that does not repeat ends. |
| play recorded sound | Sound | When the game has recorded sounds. |
A piece with a model is programmed like any other: select it and press Program with blocks in Details. The show the sprite block has a pencil next to its list: it opens the drawing of the chosen sprite or, if there is none, creates one. See Asset workshop.
The scene and the blocks#
The objects on the canvas come from the scene. They are not created on the canvas: the + button in the tab row takes you to the scene.
- Each piece tag and each zone is an object, with its tab. Identical pieces (all the coins) share a single program.
- The first spawn point is the player.
- A character is a spawn point with its name.
- A piece without a tag is scenery until you program it.
Place a coin#
Open the scene tab and, in Place pieces, click Coin and then the floor.
In a Rules project, the coin brings its rule. Here it brings its blocks, and a notice says so: "Blocks were added to make it work." Press See the blocks.
The coin, the key, the goal and the danger zone get blocks when you place them. The other prefabs are placed without logic and you program them by hand.
Program any piece#
With a loose piece selected, the Details panel shows at the top the Program with blocks button and the explanation: "It is still scenery: programming it makes it an object on the canvas."
When you press it, the editor gives the piece a tag and opens its tab on the canvas. From then on, with that piece selected, the button says See its blocks. You can do the same from the menu Scene > Program the selection with blocks and from the Program what is selected in the scene button in the Blocks panel.
The Blocks panel and the assistant#
In a blocks project, the Rules panel is called Blocks.
It lists the game's objects with their programs, opens the canvas and keeps the Test bot section. There is no New rule. In Full mode, the canvas also opens with File > Game blocks.
The AI assistant is off in a blocks project, and it says so:
There is no field to type a request. What the assistant does in other projects: AI assistant.
Test, play and export#
They work the same as in any game: Test with bot, Play and Export.
If you mark no steps, the bot uses the blocks project's script: it heads to the meta zone, if there is one, and waits for the game to end. If you mark steps in the panel, it follows them in order. How to mark them: Test bot.
The .ggx file is a game like any other: it opens in the launcher with Import .ggx. The blocks document (bloques/proyecto.json, inside the project folder) does not go into the .ggx: what travels is the script.
If the validator finds a problem on a line of the script, Take me there opens the canvas on the block that wrote that line. A block's unfilled slots also show up in Problems.
Open world with blocks#
With the Open world kind, the project comes with a cube terrain and the palette adds the Cube world category. The Crystals and cubes example uses it.
| Group | Blocks |
|---|---|
| Events | When a world block is broken, when one is placed, when the player switches slot. |
| Orders | Break, place and outline the block the player is looking at; place, break and fill by coordinates; show and remove the quick bar; save and restore the world; fly. |
| Values | The block type, the biome, the block the player is looking at and its position, the block at a point, the ground height, the chosen slot, and the block that changed with its position. |
What the cube terrain is like inside: Open world.
Switch to code#
When blocks become too small for you, the Switch to code button on the canvas turns the project into a code project.
When you accept, the editor deletes the blocks document, leaves the script with one comment per block and opens the code editor.
From there it is a project with code like the others: the panel is the Rules one again, the assistant takes requests again and the bot still wins it.
What was left out#
Blocks mode arrived with 0.3.0. It does not do this yet:
| Missing | What it means |
|---|---|
| Arbitrary keys | There is no "when key A is pressed" or "ask and wait". Blocks use the game's buttons: jump, the two actions, click and right click. |
| Touching? between two objects | "touching?" works for the player and the characters. There is no contact event between two fixed pieces. |
| Mouse position over the world | The click aims with the crosshair at the center, not with the arrow. |
| Exact jump and turn | "jump" is a push upward when the player is on the ground, and "turn" repositions it facing another way. |
| In the cube world | There are no blocks to find a biome, no block hardness, no inventory with amounts, and none to change the biomes or the seed. |
| The assistant on blocks | It is off in these projects. |
| From Rules to Blocks | There is no converter. Nor from code to blocks. |
| Errors while playing | An error that happens during a match shows in the Console with its line, but does not take you to the block. |
| Local multiplayer from the dialog | You turn it on afterwards, on the Game card. |
| 2D / 3D hybrid | A blocks game uses a single view. |
| Tile maps | A blocks game is built with pieces. Sprites are allowed: with the show the sprite block. |
| Texts in two languages | The texts you write in blocks go as they are, in a single language. |
What was tested: the walkthrough on this page, on Linux, and the Blocks mode walkthrough with a real mouse on Linux, Windows and macOS (on Apple Silicon and on Intel), with editor 0.4.0.
Next#
- Rules without code: the other way of not writing code.
- Code: where Switch to code takes you.
- Test bot
- What is missing in editor 0.4.0