ID:1748400
 
Code:
client
North()
if(mob.dir == EAST)
if(!mob.inair)
mob.inair = 1
spawn() mob.Jump()
spawn() mob.Gravity()
/* if(!mob.inair) // If ur not in the air
mob.inair = 1 // Now ur in the air
step(mob, NORTH, 3) // pass it the mob
step(mob, NORTH, 3) // pass it the mob
step(mob, NORTH, 3) // pass it the mob
step(mob, NORTH, 3) // pass it the mob
spawn() mob.Gravity()
while(mob.inair)
return*/

South()
return



mob/proc
Gravity()
var/velocity = 8
while(inair && velocity > 0)
if(step_y == 0) // we're at the bottom
if (velocity == 0)
//var/turf/dcheck = locate(x, y-1, z) // ^ one tile south
//if(dcheck.density)
inair = 0
return
step(src,SOUTH, 10)
sleep(1)

Jump()
var/velocity = 8
while(inair && velocity > 0)
step(src,NORTH, 20)
sleep(1)
velocity -= 1


Problem description:
What I want to know here is why the 'mob.Jump()' proc or the one involving Gravity () is necessary. I was given the latter in my last post on this forums, yet I neglected to ask -why- that was needed. Anyone can give me a detailed answer?


Second 'Problem'
The next thing I want to know isn't related to the code yet. But it involves the pressing of keys (as in on the keyboard) and so forth.

Can anyone guide me towards where I should look to figure out how to make keys responsive to how hard or fast you press it.

For example, double-tapping to activate run. Or like in Mario games where you can do a 'light' jump by gently pressing the button.


Misc

Also any comments or tips to make the current code less crappy will be welcomed. Right now, I'm probably going to just erase all the 'steps' proc and have them replaced with like 'move' or something.
. . No help? D:
Not sure if I'm reading your question right. You asked why gravity() and jump() are needed.. Isn't that a simple question? The answer being that gravity moves the player down, jumping moves the player up?

Seems like too easy an answer, I've surely not understood what you're asking.
. . I understand why. I just don't understand why 'spawn' had to be used-- Then again. I'm probably overthinking it.

Just when I've done code before, I just had to call the proc. Never did I have to use spawn.
Honestly, if I was you I'd delete all of that and restart. There's so many things wrong with it that it'd be better to just restart.
It would be kind if you pointed out some of the errors? Since I'm not spotting. I'll be looking over it though, finding out how to make the code more efficient.

(Starting over won't suddenly make me more aware, y'know?) Not that there's a lot to start over from.
Well I would but I don't understand the code you have written. I'm also guessing that's why no one else has answered.
In response to Gtgoku55
Without looking in-depth at the code, spawn() is used because those processes are loops that are intended to run without blocking. If you didn't use spawn, the mob would be unable to take action until those processes ended. You are essentially putting these processes into the background.

That doesn't look like it would work all that well though.
Lol. It works, albeit not in the way that I'd want. I have to place the velocity (as in pixel per seconds) just right, otherwise the jumping won't even register properly.

Though still doesn't work like how I want it. I'll have probably relook through the built in movement procs and take out the 'Steps' entirely. The goal I'm trying to achieve is basically mimic a typical jumping procedure you find in those platformers.

Pretty much like mario, where you jump and can move as you rise. (I can however, move as I fall strangely enough.)

ANYWAY, I'm babbling. Comments, tips, etc. All of that will be welcomed.

Also, thanks. . that strangely makes sense. @Mighty
Well, your biggest issue is that this system is incredibly inflexible. Gravity only occurs when someone jumps, but what if they fall of a ledge? They will just float. As for jumping, there is only one height to the jump. What about if you get a power up? Even worse, what if something can throw you? That isn't a jump, but would still fling you. Also, if you are attempting any realism at all, then your velocity should affect the rate of change your jump.

Beyond that, checking for step_y is absolutely incorrect, as you could get a step_y of zero is situations other than reaching the bottom of the jump (such as if the step was for 32 pixels in a default project).