Effective way to keep player in bounds?

What's the best way to keep the player in bounds? I am noticing that without boundary walls on the edges of the screen, the game crashes if the player attempts to move off the edge of the screen.

Perhaps listen for player position (px,py) when player is along an edge, prevent the player from moving further with gotos?

Here's what I have, but feels hacky. Open to a better solution.

(player script)
on update do
x = event.px
y = event.py
currentRoom = event.room

// preload corrected coordinates
correctTop = y
correctBot = y
correctLeft = x
correctRight = x

// top and Bottom boundaries
if y == 0 then
goto x,correctTop in currentRoom
elseif y == 13 then
goto x,correctBot in currentRoom

// left and right boundaries
if x == 0 then
goto correctLeft,y in currentRoom
elseif x == 24 then
goto correctRight,y in currentRoom

call "moveBot" // draw player sprite


I have not had this experience. When the player tries to move off the screen, it behaves the same as when they would walk into a wall. When this happens for you, what does the crash message say?

It was related to a 9-tile sprite I'm working with where px and py are in the center coordinate. When the system tries to "paint" some of the sprite off-screen, it freezes up.

I corrected this by setting invisible boundaries toward the edges so that the outer tiles of the sprite never leave the screen.