ID:262596
 
mob/proc/Air()
for(var/area/rooms/spot in oview(0,src))
if(spot.air == 1)
for(var/mob/M in world)
if(M.air_level < 50)
M.air_level ++
else
return
var/oxygen = locate(/obj/hud/oxy) in usr.client.screen
var/obj/hud/oxy/F
if(oxygen)
F.icon_state = "oxy"
if(!oxygen)
var/nooxygen = locate(/obj/hud/nooxy) in usr.client.screen
var/obj/hud/nooxy/E
if(nooxygen)
E.icon_state = "oxy"
if(!nooxygen)
usr<<"Error finding nooxy icon!"
else
for(var/mob/M in world)
M.air_level --
var/oxygen = locate(/obj/hud/oxy) in usr.client.screen
var/obj/hud/oxy/F
if(oxygen)
F.icon_state = "nooxy"
if(!oxygen)
return
if(usr.air_level == 0 && alive == 1)
Dead()
if(alive == 1)
spawn(3)Air()


All right, something I did has to be wrong here. If you go into an area with no air, the icon will change to "nooxy" but will not change back when you are in a spot with air. I can't tell if it's subtracting the air_level either.

EDIT: Oh, by the way some of the stuff that is there that looks repetitive or pointless is there for debugging purposes.

Things not to do:
if(var==1)
if(var==0)
usr in proc similar to that one

Things to do:
if(var)
if(!var)
src in proc similar to that one
In response to Ol' Yeller
I always thought it was usr.client.screen.. it can be src.client.screen?
In response to Justin Knight
Yes.
In response to Ol' Yeller
I changed what you said to change, but it still doesn't change back to the regular "oxy" state when in an area with air.

In summary, didn't work, gave the same effect as before.
Justin Knight wrote:
> mob/proc/Air()
> for(var/area/rooms/spot in oview(0,src))
> if(spot.air == 1)
> for(var/mob/M in world)
> if(M.air_level < 50)
> M.air_level ++
> else
> return
> var/oxygen = locate(/obj/hud/oxy) in usr.client.screen
> var/obj/hud/oxy/F
> if(oxygen)
> F.icon_state = "oxy"
> if(!oxygen)
> var/nooxygen = locate(/obj/hud/nooxy) in usr.client.screen
> var/obj/hud/nooxy/E
> if(nooxygen)
> E.icon_state = "oxy"
> if(!nooxygen)
> usr<<"Error finding nooxy icon!"
> else
> for(var/mob/M in world)
> M.air_level --
> var/oxygen = locate(/obj/hud/oxy) in usr.client.screen
> var/obj/hud/oxy/F
> if(oxygen)
> F.icon_state = "nooxy"
> if(!oxygen)
> return
> if(usr.air_level == 0 && alive == 1)
> Dead()
> if(alive == 1)
> spawn(3)Air()
>

All right, something I did has to be wrong here. If you go into an area with no air, the icon will change to "nooxy" but will not change back when you are in a spot with air. I can't tell if it's subtracting the air_level either.

EDIT: Oh, by the way some of the stuff that is there that looks repetitive or pointless is there for debugging purposes.

To add to Ol' Yeller's list, dont do:

if(oxygen)
if(!oxygen)


...unless the if(oxygen) is meant to change the oxygen value to cause the second check to be true. The else if statement was invented for a reason. If the first one evaluates to true, then there's no need to process the second check, resulting in faster execution.

I think you should look up what the oview() proc is. Your use of it does nothing. Your saying "Exclude the center, then exclude the surroundings" -- use the view() proc instead.

I don't see why you return if M.air_level < 50, that prevents EVERYTHING else from executing, so there's no var/oxygen or anything happening. If you're trying to exit the for loop, use break.

Hiead
You're using return quite a bit and I find that you may not want to.
What are you doing with the object variables you are defining for nooxy and oxy? I'm guessing those should be located on the screen, so we'll locate that and then check to see if the object is on the screen.
Last thing, you've usr abused. We all do it sometimes, but maybe you should stick to using src for everything you can. It prevents usr abuse. That's what I do anyway.
mob/proc/Air()
for(var/area/rooms/spot in oview(0,src))
if(spot.air)
for(var/mob/M in world)
if(M.air_level < 50) M.air_level ++
else continue
var/obj/hud/oxy/F=locate(/obj/hud/oxy) in src.client.screen
if(F) F.icon_state = "oxy"
else
var/obj/hud/nooxy/E=locate(/obj/hud/nooxy) in src.client.screen
if(E) E.icon_state = "oxy"
else src<<"Error finding nooxy icon!"
else
for(var/mob/M in world) M.air_level --
var/obj/hud/oxy/F=locate(/obj/hud/oxy) in usr.client.screen
if(F) F.icon_state = "nooxy"
if(!src.air_level && src.alive) src.Dead()
if(alive) spawn(3) src.Air()


I've also compacted it a little so it cuts down on the tabbing. You can always.. un-compact it later. If you don't want it like that.
In response to CaptFalcon33035
Thanks Hiead and Captain Falcon, as you guys said, I was having problems with my if/else sequences. I think I figured because they were tabbed from the for loop, it would keep going.

I'll edit the code to what I wanted it to do, it needs a couple minor things to be corrected in addition to what you guys showed me.

CaptFalcon, is there any reason you used usr.client.screen on the else statement, or was that a typo?
In response to Justin Knight
I actually just copy and pasted your code, tabbed it, and compacted it as well as to a few minor changed. I must've missed that. It should be src.client.screen
In response to Justin Knight
runtime error: Cannot modify null.icon_state.
proc name: Air (/mob/proc/Air)
source file: Air.dm,41
usr: Thewar364 (/mob)
src: Thewar364 (/mob)
call stack:
Thewar364 (/mob): Air()
Thewar364 (/mob): Air()

Hm.. I did what you guys said but it still doesn't work, gives me a nasty runtime now too.

        if(oxygen)
F.icon_state = "oxy"


That's lines 40 and 41
In response to Justin Knight
Bump.. because my post is more important than the govegtos flame post.
In response to Justin Knight
Delete your bump, save yourself. >_>

Anyways, just do an if(F) check.