ID:139699
 
Code:
//ELEVATION------------
turf
var elevation = 0
elevation
icon = 'elevation.dmi'
elev_1
icon_state="1"
elevation = 1
elev_2
icon_state="2"
elevation = 2
elev_3
icon_state="3"
elevation = 3
elev_4
icon_state="4"
elevation = 4

mob
Move()
if(istype(src.loc, /turf/elevation) in get_step(src,dir))
var/turf/currETurf = src.loc
var/level = currETurf.elevation

var/turf/nextETurf = get_step(src,dir)
var/nextLevel = nextETurf.elevation

if((level + 1 != nextLevel) && (level - 1 != nextLevel) && (level != nextLevel))
return 0
else
return ..()
else
return ..()


Problem description: So I know at least a few people have been doing elevation in their games, but the code I've been finding has usually been very specific to individual turfs. Like, people would have a cliff turf or a certain grass turf that would have the elevation. All I want to do is set some transparent overlay turfs to have a certain elevation property so that I can reuse those overlays wherever I think it's appropriate. So far this code snippet has been doing nothing for me. I just walk on to the elevation 3 from elevation 0.

What's wrong with the code? Thanks!

Are you working with 2d or isometric?
In response to OrangeWeapons
2d
A. The check should most likely be in the Enter() code on the turf, not in Move().
B. mob/Move() sends you the new turf as an argument, there's no reason to attempt finding it.
C. I'm not even sure what that first if() is supposed to be doing.
D. That if() you have checking the elevations will return false, unless you're stepping into a multi-higher/lower elevation.
E. Probably some other stuff
In response to Falacy
Okay, I'll try using Enter() then

The first if() is supposed to check if the mob's next step could be an elevation turf. If it isn't an elevation turf, then bypass the override and continue as normal. I thought it'd be a bit more efficient.

EDIT:

Okay, so I know this Enter() code works, it's just a matter of how to stop it from trying to proceed if the mob's turf is null. I get a runtime error without if(istype(src, /turf/elevation)), but with it, the player can step from elevation 3 to elevation 0 without being stopped.

The if(!isnull(src)) isn't catching the null. What do?


//ELEVATION------------
turf/var/elevation

turf
elevation = 0
Enter(atom/movable/O)
if(!isnull(src))
var/turf/currETurf = O.loc
var/level = currETurf.elevation

//var/turf/nextETurf = get_step(O,dir)
var/nextLevel = src.elevation

if((level == nextLevel) || (level + 1 == nextLevel) || (level -1 == nextLevel))
return 1
else return 0
else return ..()


EDIT 2:

OKAY! :D I got it working. i used if(!isnull(O.loc))

Thanks for pointing me towards Enter()! Solved all my problems
I thought I'd explain why you encountered the problem, even if you resolved the issue in a different way, because you might learn something for later on.

if(istype(src.loc, /turf/elevation) in get_step(src,dir))
get_step returns a turf, and you're trying to search for a boolean value in that turf's contents list. As this never returns true, you're never actually even executing the code in question.

One hint on 'if((level + 1 != nextLevel) && (level - 1 != nextLevel) && (level != nextLevel))', just test if(abs(nextlevel-level) <= 1) instead.