ID:1730777
 
(See the best response by A.T.H.K.)
Code:
client
North()
if(src.mob.dir == East)
if(src.mob.inair==0)
src.mob.inair = 1
src.Move(locate(step(src, NORTH,10)))
Gravity(src.mob)
South()
return
Northeast()
return
Northwest()
return
Southeast()
return
Southwest()
return

proc
Gravity(mob/M)
while(M.inair == 1)
var/turf/dencheck = locate(M.pixel_x,M.pixel_y-6,M.pixel_z/*M.step_y -= 6*/)
sleep(10)
if(dencheck.density == 1)
M.inair = 0
return
else
M.loc=locate(M.pixel_x,M.pixel_y-6,M.pixel_z/*M.step_y -= 6*/)


Problem description:
Hello, Byonders. I don't mean to be a bugger, but this seriously has me stumped. I've been observing source codes, I'll admit. But for this attempt, I've been trying to get a proc done on my own.

Basically, the Gravity proc is supposed to activate whenever I move up north, then make me move a few pixels done every few ticks. Buut.. everything I move north, I just crash.

Give me guidance, please. And I realize that the code is incomplete, considering I don't have a portion that checks whether I'm in the air so I can't infinitely 'jump'.. but eh.
Best response
You don't need to use == 1 or == 0 when only using a TRUE or FALSE variable, if you were using inair = 2 then that's different.

if(dencheck.density) // equals TRUE or 1

if(!dencheck.density) // equals FALSE or 0

while(M.inair) // equals TRUE or 1

if(dencheck.density) // equals TRUE or 1
Change spawn to sleep will fix the problem. I always have this problem.
Applied A.T.H.K's suggestions. Made the code cleaner, I suppose. But I'm still crashing whenever I move North.
You aren't sleeping the loop.
ahhh. I forgot to mention I did in fact change 'spawn' to sleep. Gonna update the DM tag to express the change.
Is a new loop being created every step, regardless of whether one is already going?
What do you mean by "crash?" It looks to me like you're misusing the locate() proc, sending you to the void (usually black screen) but that's not crashing.
http://gyazo.com/95df130423303d274c7a7347e78fb888


^ literally crashes. Ignore the icons.
client
North()
if(mob.dir == EAST)
if(!mob.inair)
mob.inair = 1
step(mob, NORTH, 10) // pass it the mob
spawn() mob.Gravity()

mob
Gravity()
while(inair)
if(step_y == 0) // we're at the bottom
var/turf/dcheck = locate(x, y-1, z)
// ^ one tile south
if(dcheck.density)
inair = 0
return
step(src, SOUTH, 6)
// This makes us step south 6 pixels
sleep(10) // isnt this slow for animation?
// I would personally put 5 or less


If I understand what you're doing, this should be an improvement. I haven't compiled it or anything but it seems right. One of your problems is how you're trying to use Move() and locate()

locate() has a number of ways you can use it, but you can't give it pixel coordinates as far as I'm aware. You need to give it type, xyz, tag, or textref parameters. I used xyz here.

Move() will move a mob, but jamming locate() and step() in the parameters.. that doesn't seem right. step() already moves you there if it can, and returns 1 on success, 0 on failure. locate(1), thats not valid. Plus, you're trying to move again after that with Move(). Just use step() here.

I would also probably integrate the stuff from client/North() into mob/Move() as well, just seems better organized, but it works either way.
I appreciate all the help, guys.

Moving onto Kitsueki, yeah. The issue was that I wanted to make my system purely pixel-based for smoothness. But after reading the reference, apparently you can make your step speed based off of pixel. (Lrn something new everyday)

I added your code and adjusted it so that it had no errors. Funny enough, it did make me crash, and it did go above. Yet the gravity proc didn't kick in. Plus after that, I got runtime errors.

http://gyazo.com/3351dd36aafae9e4a37891a82f73a52c

I'm -really- confused as to why my code nor any other is working. It should.. shouldn't it?
You can make it purely pixel based, but you'll have to set up some extra procs for that. I messed that up pretty bad after reviewing it, one moment.

Okay, I had to back up the step() and sleep() calls, they shouldn't have been under that if() statement, it was causing the infinite loop. This shouuuuld solve it.
Working partially. *Thumbs up* I think I can take it from here. Thanks for the help, Kits.

EDIT:

For those out there that may look over the topic to learn too. I think one of my issues was that I just placed the 'proc'. When I messed around with Kitsueki's code, it worked fine when the proc was set under 'mob'. But when I just flat out tried to create (What I believe is called a 'global' proc???) one without labels, I began getting errors again.