Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

TIC-80

Fantasy computer for making, playing and sharing tiny games. · By Nesbox

How mget() and fget() work in lua please tips for idiots

A topic by Dev_028 created Aug 18, 2023 Views: 254 Replies: 4
Viewing posts 1 to 3

help, I don't know how to use mget() and fget

essentially, mget(x, y) takes a tile's x and y position on the map, and returns the tile id of it (a number) . It's often used for collision in platformers.

Fget(tile_id, flag) works in a similar manner, however fget() returns a boolean value. it will return true if the tile ur checking has that flag, and false if it doesnt. To define a tile's id, go to the sprite editor, and click the little switch underneath the sprite editor logo (at the top) You'll then be in advanced mode, and see some new stuff appear. Focus on the numbers with boxes on the left. These are the flags you can use to define how a tile may act. For example, clicking the button next to 0 will make a red dot appear, and will make this tile have a flag of 0. This could be used to determine whether a tile is solid or semi-solid. You can also use multiple flags per tile, but keep in mind you only have 8 of them.

Hope this helps you in some way!

:D

Thanks dude!

(2 edits)

mget usually works for collision on a tile. Take this function: map(0,0)

Then you have a player:

spr(1,x *8,y *8)

WHY *8 here? Because a tile is usually 8 by 8. And we need it for collision. This is my personal favorite approach. Alternatively you could divide it in the mget function by 8.

So if you want to make a collision, with my style:

if mget(x,y)==tile_1 then print(“cool”) end It will print cool.

Now mget(x,y)==tile_1 is specific to map(0,0)

So you what you want to do is to have mget(x+levelx,y+levely)==tile_1 to make it dynamic to each level.

map(levelx,levely) spr(1,x8,y8) –if you win, the map moves down by 17 if levelWin then levely = levely+17 end

–if you collide with tile_1 then you print cool if mget(x+levelx,y+levely)==tile_1 then print (“cool”) end

(1 edit)

of course you need x and y.

so x = 10; y = 10 should be away from a function associated with TIC(). You could use it in BOOT()