ID:935137
 
(See the best response by Kaiochao.)
Code:
mob
Move()
if(!get_step(src,EAST))
loc=locate((world.maxx-world.maxx+1),y,z)
else if(!get_step(src,WEST))
loc=locate(world.maxx,y,z)
else if(!get_step(src,NORTH))
loc=locate(x,(world.maxy-world.maxy+1),z)
else if(!get_step(src,SOUTH))
loc=locate(x,world.maxy,z)


Problem description:
Basically I'm trying to make it so if you bump the max coordinate possible you go to the other side of the map

get_step sorta works but it works at x 499 instead of x 500.

is there any better way to tell that i have reached the end of the map when going in a certain direction?
Check the turf in front of them and run an isturf() check on it.
Basically the problem is Move isnt called if you're trying to move against the edge of the map its the issue lol.
You could use Move() like this maybe:
mob
Move()
if(x = 1 && dir = WEST)
loc = locate(maxx, y, z)
if(x = maxx && dir = EAST)
loc = locate(1, y, z)
//so on and so fourth




The problem is that above code won't work unless you call ..() first and the problem with that is that it will move you as you hit the max x or max y instead of you hit it then move again then it will take you there.
Best response
It's not seamless or pretty, but it gets the job done.
var d2o_x = list(  0,  0,  0,  1,  1,  1,  0, -1, -1, -1 )
var d2o_y = list( 1, -1, 0, 0, 1, -1, 0, 0, 1, -1 )
#define dir2x(dir) d2o_x[dir]
#define dir2y(dir) d2o_y[dir]
#define dir2offset(dir) list(dir2x(dir), dir2y(dir))

#define wrap(n, min, max) (((n) < (min)) ? ((n) + (max)) : (((n) > (max)) ? ((n) - (max)) : (n)))

mob/Move(new_loc, new_dir) return !new_loc && new_dir ? ..(locate(wrap(x + dir2x(new_dir), 1, world.maxx), wrap(y + dir2y(new_dir), 1, world.maxy), z), new_dir) : ..()


Expanded:
mob/Move(new_loc, new_dir)
// Chances are you're moving off the map
// if this condition passes.
if(!new_loc && new_dir)
var nx = x
var ny = y

// Get the false location
// (what your coordinates would be
// if you weren't stopped by the edges)
if(new_dir & EAST)
nx ++
else if(new_dir & WEST)
nx --
if(new_dir & NORTH)
ny ++
else if(new_dir & SOUTH)
ny --

// Wrap the coordinates around
if(nx > world.maxx)
nx -= world.maxx
else if(nx < 1)
nx += world.maxx
if(ny > world.maxy)
ny -= world.maxy
else if(ny < 1)
ny += world.maxy

// Perform the default behavior
// with the new, wrapped location.
return ..(locate(nx, ny, z), new_dir)

// Move normally.
return ..()

edit: Made some typos, but they should be fixed now.
http://www.byond.com/forum/?post=916683

This seems to match your issue, and was recently dealt with, using many replies that worked.
In response to Kaiochao
Kaiochao wrote:
It's not seamless or pretty, but it gets the job done.
> var d2o_x = list(  0,  0,  0,  1,  1,  1,  0, -1, -1, -1 )
> var d2o_y = list( 1, -1, 0, 0, 1, -1, 0, 0, 1, -1 )
> #define dir2x(dir) d2o_x[dir]
> #define dir2y(dir) d2o_y[dir]
> #define dir2offset(dir) list(dir2x(dir), dir2y(dir))
>
> #define wrap(n, min, max) (((n) < (min)) ? ((n) + (max)) : (((n) > (max)) ? ((n) - (max)) : (n)))
>
> mob/Move(new_loc, new_dir) return !new_loc && new_dir ? ..(locate(wrap(x + dir2x(new_dir), 1, world.maxx), wrap(y + dir2y(new_dir), 1, world.maxy), z), new_dir) : ..()
>

Expanded:
> mob/Move(new_loc, new_dir)
> // Chances are you're moving off the map
> // if this condition passes.
> if(!new_loc && new_dir)
> var nx = x
> var ny = y
>
> // Get the false location
> // (what your coordinates would be
> // if you weren't stopped by the edges)
> if(new_dir & EAST)
> nx ++
> else if(new_dir & WEST)
> nx --
> if(new_dir & NORTH)
> ny ++
> else if(new_dir & SOUTH)
> ny --
>
> // Wrap the coordinates around
> if(nx > world.maxx)
> nx -= world.maxx
> else if(nx < 1)
> nx += world.maxx
> if(ny > world.maxy)
> ny -= world.maxy
> else if(ny < 1)
> ny += world.maxy
>
> // Perform the default behavior
> // with the new, wrapped location.
> return ..(locate(nx, ny, z), new_dir)
>
> // Move normally.
> return ..()
>

edit: Made some typos, but they should be fixed now.

Doesn't seem to work at all for some reason i just sit at maxx or maxy.
In response to Gokussj99
It works for me in a clean test project. Are you overriding Move() somewhere that could possibly be interfering with it?

I should've also mentioned, it doesn't work at all with pixel movement.
In response to Kaiochao
Kaiochao wrote:
It works for me in a clean test project. Are you overriding Move() somewhere that could possibly be interfering with it?

I should've also mentioned, it doesn't work at all with pixel movement.

No I'm not overriding it anywhere

Could using step to move cause that issue?


EDIT: That was the issue thanks a lot kaio.
Here this works:
mob
var
old_x
old_y
old_z

proc
update_pos()
if(x)
old_x = x
old_y = y
old_z = z

Move()
if(old_x == 1 && dir == WEST)
loc = locate(world.maxx, y, z)

if(old_x == world.maxx && dir == EAST)
loc = locate(1, y, z)

if(old_y == 1 && dir == SOUTH)
loc = locate(x, world.maxy, z)

if(old_y == world.maxy && dir == NORTH)
loc = locate(x, 1, z)

..()
update_pos()


EDIT: Didn't read ahead to well there, but hey more solutions can't be bad.
In response to GreatFisher
You should probably include the diagonal directions as well.
In response to Gokussj99
Gokussj99 wrote:
Could using step to move cause that issue?


EDIT: That was the issue thanks a lot kaio.

Yeah. After a bit of testing, it seems that step() returns 0 without even calling Move() when you're moving off the edge, but it does call Move() every other time to detect collisions. It's not possible to override step() to add the wrapping behavior.
In response to Boubi
I made a very simple solution, I assumed that he could probably do the more in depth parts himself.