Detecting tiles near the player

I have had some trouble in the past figuring this out, so this is a tutorial on how to detect what type of tiles are near the vicinity of the player. Here is the code:

on draw do
PX = event.px
PY = event.py
PY += 1
Variable = name PX,PY
if Variable=="YourTileHere" then
tell "YourTileHere" to
call "YourFunctionHere"
end
end
end

This code checks if the tile "YourTileHere" is beneath the player, and tells its code to call the interact function. "Variable" is the name of the variable which stores the tile ID. If you want to check the tile the player is currently on, use this:

on draw do
PX = event.px
PY = event.py
Variable = name PX,PY
if Variable=="YourTileHere" then
tell "YourTileHere" to
call "YourFunctionHere"
end
end
end

In both instances, it sets up two variables named PX, and PY, which represent the players location, if you want to change the location by one, for instance, you can do this: PY -= 1 or PX += 1 (something to keep in mind, the coordinates for PY go one tile higher when you do PY -= 1) Also this code just stores the name of the tile in "Variable":

Variable = name PX PY

I hope this tutorial helps!

1 Like