proc
Gravity(var/mob/per)
if(per.dir==EAST||per.dir==WEST)
if(per.inair == 1 && per.frozen == 0 && per.flying == 0)
var/turf/check = locate(per.x,per.y-1,per.z)
var/mob/check2 = locate(per.x,per.y,per.z)
if(check.density == 1||check2.density == 1)
per.inair = 0
return
if(check.trap == 1)
per.loc = locate(4,98,2)
per.inair = 0
return
else
per.loc=locate(per.x,per.y-1,per.z)
sleep(2)
Gravity(per)
else
return 0
ID:272372
![]() Jun 19 2008, 6:41 am
|
|
Well the first part I'm having trouble with, whenever I try to jump on a players head I go right through them, but all the other directions seem fine. I need to get that fixed, and if possible, is their a way to make it so when I land on a players head that is in the air I jump an extra time, kinda like a spring? Here's my code so far.
|
Element Hero creator wrote:
> Gravity(var/mob/per)
When making args, as far as I know you don't have to start it with var/ . Change it to this: Gravity(mob/per) Technically, the code you have at the moment should give you a runtime error. I'm going to assume you didn't get the error because you have a custom skin without an output box. |
Yeah your right, I do get runtime errors, but I just tried your way and I still get...
runtime error: Cannot read null.density proc name: Gravity (/proc/Gravity) source file: Main.dm,8 usr: Element Hero creator (/mob) src: null call stack: Gravity(Element Hero creator (/mob)) Gravity(Element Hero creator (/mob)) Gravity(Element Hero creator (/mob)) Gravity(Element Hero creator (/mob)) Gravity(Element Hero creator (/mob)) Gravity(Element Hero creator (/mob)) Gravity(Element Hero creator (/mob)) Gravity(Element Hero creator (/mob)) Gravity(Element Hero creator (/mob)) Gravity(Element Hero creator (/mob)) Gravity(Element Hero creator (/mob)) Gravity(Element Hero creator (/mob)) Gravity(Element Hero creator (/mob)) Element Hero creator (/client): West() |
Adam753 wrote:
When making args, as far as I know you don't have to start it with var/ . Change it to this: Correct, you don't have to do it. But adding it anyway has no effect, and isn't really a mistake. It makes no difference at all, so it isn't going to fix any problem. |
Really? Because when I went to see my friend's runtime error, we ttok out the var/ bit in an arg, and the problem was solved.
Anyway, I read your runtime error, and I can see the probem: it lies in these few lines. var/turf/check = locate(per.x,per.y-1,per.z) There will always be a turf below per, because you can't not have a turf. But you're checking for a mob in locate() coordinates. However, locate() returns a TURF... so you're effectively asking it to look for a mob that's a turf. Then you're asking for it's density, which it can't give you, because it can't find a mob that's a turf! The solution: //I assume you are looking for a mob here. You want to do this: |
Adam753 wrote:
Really? Because when I went to see my friend's runtime error, we ttok out the var/ bit in an arg, and the problem was solved. It was actually solved by something different then, because it definitely makes no difference. If it wasn't proper syntax, it'd have made a compile-time error, not a runtime. But you're checking for a mob in locate() coordinates. However, locate() returns a TURF... so you're effectively asking it to look for a mob that's a turf. Then you're asking for it's density, which it can't give you, because it can't find a mob that's a turf! This is quite inaccurate, though. It's a common misconception, but that line (var/mob/check2 = locate(per.x,per.y,per.z)) doesn't actually do anything mob related at all, it doesn't search for mobs, or anything. It simply sets 'check2' to what locate(coordinates) returns, which is either a turf, or null if the coordinates are invalid. The check2 variable is defined as a /mob type, but that doesn't mean it contains a mob reference or "looks for one" or something. In fact, it doesn't mean anything, it doesn't affect the actual code's operation. Defined variable types are used almost exclusively for compile-time error checking, and they do not set the variable's value or affect it. This error's cause would have to be locate() returning null, therefore the vars are set to null and then the code tries to access null.density. The error could be caused by either variable. For the locate() in the setting of check, it could return null if either per is located in null itself, or per.y == 1 therefore a coordinate of 0 is inserted. For the second locate() to return null it could only be the former, but that whole call is superfluous because the same value (per's location) is accessible by simply per.loc, like you're aware. The solution: > //I assume you are looking for a mob here. You want to do this: How do you think that would work, though? If check2 equals per, how would checking if it doesn't change it so it equals a different mob, if any, or be of a different benefit? Rather, it would just make the code under that if() check not run. You're actually going to have to use a for() loop so you can find multiple mobs inside the turf, an alternative so skipping the mob per is using the list from orange(per) (with a range of 0 so it only includes that one tile), which wouldn't include per. |
To this: