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:
sprite_properties
The non-solid floor sprites are placed in the 1st row...slots 01-15
The non-solid damaging sprites are placed in the 3rd row...slots 33-47
The solid wall tiles are placed in the 5th row slots...slots 66-79

Now we can test for sprite properties by checking it's ID:

--first we'll take the tile the player is standing on and log it into "tile"
tile=mget(player.x, player.y)

--now we'll test it for damage properties...remember they're stored between 33-47
if tile>=33 and tile<=47 then
 reduce_player_health()
end

I will only place collidable tiles after the solids row

Clone this wiki locally