Log In  

I generated a map and use mset to update the sprites on the map. But when I tested to print out the sprite number using mget and the coordinates of my cursor, it always returns the same sprite number. I am confused about where I did wrong.

This is what I use for drawing the map and updating.

function draw_game()
    map(0,0,0,0,16,16)
    update_map()
    draw_house()
    draw_cows()
    cow_grazing_anim()
    draw_cursor()
    print("⧗:"..game_time,60,8,1)
end

function update_map()
    for g in all(grass) do
        mset(g.x,g.y,g.s)
    end
end

And I use this to check with mget, it returns all the same sprite number.

if btnp(4) then
            --state=2
            local t=mget(to_grid(cs.x,cs.y))
            printh("x:"..cs.x.."y:"..cs.y..",spr:"..t)
    end

I attached an image with the map I draw and the grass sprite should be from 50 to 53 but I get like all 53 or all 52. which is weird. I have attached my cartridge below, would be great if someone enlighten me on what I did wrong.

Cart #mimazihofu-0 | 2020-09-03 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA

P#81462 2020-09-03 04:03

The to_grid() function returns a table, so you can’t just call mget(to_grid(...)).

You can either use mget(unpack(to_grid(...))), or make it so that to_grid() returns a tuple: return x/8,y/8.

P#81478 2020-09-03 15:43

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-03-28 16:54:47 | 0.009s | Q:13