Hey there, I'm not super familiar with coding and I'm working on my first game, which at one point requires the player to bump into a tree, which then drops a collectable log to pick up. The trouble is, I don't know how to actually make the log drop where I need it to when I'm reusing the tree graphic. Is there a way to tie the collectable drop to the specific tile iteration rather than an x,y coordinate?
In an event handled by an instance of a tile (like interact
) you can use event.x
and event.y
to get the tile instance's coordinates.
Some example code that would swap in a log
tile to the right of the tree being interacted with:
on interact do
x = event.x
x++
tell x,event.y to
swap "log"
end
end
Works perfectly, thanks for this!
By the way, if I wanted it to drop to the left or bottom instead of the right, how would I adjust the code? (very new to this!)
For the example above, here are all directions, use the lines you need:
//left
x = event.x
x--
//right
x = event.x
x++
//top
y = event.y
y--
//bottom
y = event.y
y++
Also remember to change "tell x,event.y to" to "tell event.x,y to" if you're using top or bottom.