ID:1629016
 
Instead of letting players hit the edge of the map this code will stop them and turn them back around before they reach the edge of the map.

By defining the value of boundary (default 10) you can choose how close to the boundary the player can get.

/*
Invisible Boundary
Author: Zecronious
Terms: Public Resource
*/


#define boundary 10

mob
var/turningBack = 0

Move()
// Is currently turning back
if(turningBack) return ..()

// In bounds
if(x <= boundary || y <= boundary)
turnAroundAndGoBack()
return 0
if(x >= world.maxx - boundary || y >= world.maxy - boundary)
turnAroundAndGoBack()
return 0

// Return the value of the original Move()
return ..()

proc
turnAroundAndGoBack()
dir = turn(dir, 180)
turningBack = 1
step(src, dir)
turningBack = 0
You should be returning 0. null is not 0, and the standards say that Move() returns one of: "0 if the movement failed", "1 if the movement is a jump", or "the number of pixels moved if the movement is a slide."

best to not modify what default procs return unless you have good reason.
Also, a lot of your variables you define in your various tutorials should be declared as tmp. Having those variables saved could confuse some people when certain issues start cropping up in their projects which utilize saving.
I'll look into tmp but people should define the variables however they want. I personally use a player object called Stats and I put anything I want to save into that.
In response to Ter13
Explain please. The example in the documentation of .. says to do it this way for Move().
The issue isn't ..(), the issue is where you are returning null.
In response to Ter13
Ter13 wrote:
The issue isn't ..(), the issue is where you are returning null.

Where am I doing that?
In response to Zecronious
Zecronious wrote:
Ter13 wrote:
The issue isn't ..(), the issue is where you are returning null.

Where am I doing that?

        if(x <= boundary || y <= boundary)
turnAroundAndGoBack()
return
if(x >= world.maxx - boundary || y >= world.maxy - boundary)
turnAroundAndGoBack()
return
Changed it to 0 despite making no difference what so ever. But hey.
It makes a difference, because null is not zero, and if you are releasing something for public consumption, changing the behavior of a built-in function in a manner such as this could have unintended consequences.
In response to Ter13
Yes but it didn't.
Yes but it didn't.

You aren't the end-user. All it takes is one if(.==0) and your snippet will mess someone else's project up.