ID:170514
 
This is my code for pushing a crate around. It works but when you push the crate into a dense object a runtime error is born. How would I get it to where if it,the crate, is pushed into a dense object it doesn't go anywhere, with out runtime errors.

mob
player
Bump(obj/O)
if(istype(O,/obj/crate))
flick("push",src)
step(O,src.dir)
step(src,src.dir)


The runtime error occurs every time the crate is pushed into a dense a.t.o.m. If you keep pushing it into the wall, runtime errors keep coming until it disconnects you from the game. Maybe its not caused by the crate touching a dense atom but maybe its when the player can't walk into the crate, I dont know. Please assist.

Runtime Error:
_______________________________________________________
runtime error: Maximum recursion level reached (perhaps there is an infinite loop)
To avoid this safety check, set world.loop_checks=0.
proc name: Bump (/mob/player/Bump)
usr: Leon (/mob/player/Stars)
src: Leon (/mob/player/Stars)
call stack:
Leon (/mob/player/Stars): Bump(the crate (/obj/crate))
Leon (/mob/player/Stars): Bump(the crate (/obj/crate))
Leon (/mob/player/Stars): Bump(the crate (/obj/crate))
Leon (/mob/player/Stars): Bump(the crate (/obj/crate))
Leon (/mob/player/Stars): Bump(the crate (/obj/crate))
Leon (/mob/player/Stars): Bump(the crate (/obj/crate))
Leon (/mob/player/Stars): Bump(the crate (/obj/crate))
Leon (/mob/player/Stars): Bump(the crate (/obj/crate))
Leon (/mob/player/Stars): Bump(the crate (/obj/crate))
Leon (/mob/player/Stars): Bump(the crate (/obj/crate))
...
Leon (/mob/player/Stars): Bump(the crate (/obj/crate))
Leon (/mob/player/Stars): Bump(the crate (/obj/crate))
Leon (/mob/player/Stars): Bump(the crate (/obj/crate))
Leon (/mob/player/Stars): Bump(the crate (/obj/crate))
Leon (/mob/player/Stars): Bump(the crate (/obj/crate))
Leon (/mob/player/Stars): Bump(the crate (/obj/crate))
Leon (/mob/player/Stars): Bump(the crate (/obj/crate))
Leon (/mob/player/Stars): Bump(the crate (/obj/crate))
Cloudiroth (/client): North()
__________________________________________________________
The problem is caused because the crate can't move since it's blocked. When the player tries to step into it, it bumps the crate again, which still can't move since it's blocked.

It's pretty easy to fix, though. step() returns a 1 if it succeeds/can move, and a 0 if it doesn't. Simple check if the crate's step() worked before doing the player's step().
mob
player
Bump(obj/O)
if(istype(O,/obj/crate))
flick("push",src)
if(step(O,src.dir))
step(src,src.dir)
In response to Jon88
Thanks that works.