In my exploration game, there is a point where the player character can become glow in the dark, which allows you to find objects in a dark room. This works in two ways - one by changing the sprite to a different tile when walking on black squares. The other way is to make certain objects appear when the player is near them by telling them to call an event called "glow". I used to following code in the player's Update event handler, which works fine except for one issue which causes a crash.
if glowinthedark==1 then
lightupx = event.x
lightupy = event.y
lightupy--
tell lightupx,lightupy to
call "glow"
end
lightdownx = event.x
lightdowny = event.y
lightdowny++
tell lightdownx,lightdowny to
call "glow"
end
lightleftx = event.x
lightlefty = event.y
lightleftx--
tell lightleftx,lightlefty to
call "glow"
end
lightrightx = event.x
lightrighty = event.y
lightrightx++
tell lightrightx,lightrighty to
call "glow"
end
end
This works great except for when the player tries to move to the top or bottom of the screen, which causes the game to crash. I've tested different possibilities and it is definitely this script specifically that's causing the problem.
It doesn't crash if the player goes to the sides of the screen, and if I block off the bottom or top of the screen with wall tiles so the player cannot get within one tile of the top or bottom edge the problem also doesn't occur. I thought it could be something to do with the player trying to "tell" tiles that don't exist, but if that were the case I'd expect it to happen at the horizontal edges as well, and not just the vertical edges.
Does anyone have any idea why this might be happening only when moving to the vertical edges of the screen and not the horizontal edges? And even more helpfully, does anyone know how I could stop this from happening at all?
Many thanks in advance!