Skip to content

Using mset() and mget() functions

Bear Thorne edited this page Nov 1, 2017 · 14 revisions

!!PAGE UNDER CONSTRUCTION!!

In it's most basic form, the map is a way of organizing graphics.
You can draw in your sprites in the map editor...but that's only half the story.
There wouldn't be much point if you couldn't read data back from the map.
To do this we use:

mget(cell_x,cell_y)

This takes map coordinates as arguments, and returns the ID number of the sprite drawn in that cell.
In this way we can alter game behaviour based on sprites. Some options include:
collision detection
trip wires
alter player speed based on terrain
damage inflicting tiles

These gameplay mechanics are common in a variety of games.

Another useful thing to do with the map is alter the sprites.
To do that we use:

mset(cell_x,cell_y,sprite_ID)

This takes cell coordinates, and a sprite ID, and places that sprite in that cell.
Some uses for this include:
opening/closing doors
breakable walls
spiked floor traps

Again some very old stand-bys in games.

Often times you'll use both of these together.
one to read the map and the other to modify it.
Let's look at a few examples:

DETECTING TILE PROPERTIES

The easiest way to assign properties to sprites is to arrange similar tiles together.
For example:

Clone this wiki locally