ID:1040799
 
(See the best response by NNAAAAHH.)
Code:
obj
Fire
icon ='Dark.dmi'
layer = 9
Crossed(O)

for(var/mob/M in orange(0,src))
world<<"Your are in a damage area!"
O.HP - 10
sleep(10)


Problem description:
I am trying to make and object work to where if you are stepping in it, it will damage you every second for as long as you are under it. But it will only run the for loop once.
Change that for() to a while().

Not sure how Crossed works (never used it) you can try Enter() or Entered()
In response to A.T.H.K
I'm pretty sure Enter() for an object wouldn't work unless you place the mob into the obj's contents.
In response to A.T.H.K
mob/var{OnFire=0;hp=100;}
turf/Entered(mob/m)//Once a mob is in the fire, light them up. Replace with Enter() if you want them to catch flame just by attempting to enter the fire.
for(var/obj/fire/f in oview(src,0))
m.Ignight()
return ..()
mob/proc/Ignight()
if(OnFire) return
OnFire=1
var/TimesLoopedOnFire=1
while(TimesLoopedOnFire)
hp-=min(hp,10*TimesLoopedOnFire)
var/StillBurning=0
for(var/obj/fire/f in oview(src,0))//you could probably swap with in loc instead of in oview()
StillBurning=1
TimesLoopedOnFire++
break//This is so you don't gain extra damage from more than one instance of fire, remove if not desired effect
if(!StillBurning)//if no fire is located, start removing damage done
TimesLoopedOnFire--
OnFire=0


Sorry it took me so long to get around ot helping you properly, Arch. I was kept rather busy by neighbors and friends.
obj
Fire
icon = 'Dark.dmi'
layer = 9
Crossed(O)
..()
spawn(-1) DamageLoop(mob/O) // Crossed runs only once when it occurs, so you have to spawn in the loop
proc
DamageLoop(mob/O)
while(O.loc == loc) // check to make sure the target is still in range, if not the loop will end, finishing the proc
world << "You are in a damage area!"
O.HP -= 10
sleep(10)


This should work, I just coded it from memory since it's really simple. Basically, you were looping through all the mobs in range of the Fire obj, and taking HP for that single mob (O) for every instance, which isn't desirable as far as I'm aware.

Instead, I just used a while loop and checked that the locations match. Once that isn't true anymore, the loop will end, thus terminating the proc.

I believe Uncross() and Uncrossed() have to occur before Cross() and Crossed() for the same obj can run again, so stacked procedures shouldn't be an issue.

However, if you use pixel movement then this wont be visually correct, as only the loc is checked. The code will work, only you don't have to stand directly on the fire to be receiving the damage.

Edit: NNAAAAHH posted as I was writing this.

Edit2: He added a good check into this, I forgot to take account for other objs causing the damage to be there as well. The fix was simple, given you are okay with an extra variable being added to your mobs:

obj
Fire
icon = 'Dark.dmi'
layer = 9
Crossed(mob/O)
..()
spawn(-1) DamageLoop(O) // Crossed runs only once when it occurs, so you have to spawn in the loop
proc
DamageLoop(mob/O)
if(O.isBurning) return // if O is burning, we don't want another DamageLoop() running
O.isBurning++ // O is now burning
while(O.loc == loc) // check to make sure the target is still in range, if not the loop will end, finishing the proc
world << "You are in a damage area!"
O.HP -= 10
sleep(10)
O.isBurning-- // no longer burning since the loop has ended

mob/var/isBurning
In response to Kitsueki
Yours is the more straightforward one. One problem though: you're typecasting O as a mob without actually checking.

And to solve the pixel movement issue, just use the locs variable instead of loc.
while(loc in O.locs)
O << "You are in a damage area!"
O.take_damage(10)
if(!O || O.dead) return
sleep(10)
In response to Kitsueki
Sorry, he didn't include enough details on what he wanted.

Anyway, the second example you have wont work properly at all, you add to isBurning each time it loops, then only subtract from it once, after it is finished looping.

The goal he is trying to achieve is to increase the damage for however long you're inside of the fire, then slowly put it out over time, such as how fire works in most games. Other games only give a simple damage over time while on fire(Skyrim for example).

Thank you for the clearification on Crossed() and thank Kaiochao for pointing out locs, which I somehow neglected.

[EDIT] I know what the OP is intending because I know him elsewhere and he asked for help on this issue the day before posting this. [END EDIT]
Yeah, Kaiochao, I noticed that the type can get passed wrong too. I had forgotten to change that, thanks for pointing it out.

I can see how the locs variable would work here, and to be honest I didn't know it existed, haha.

NNAAAAHH: Ah, you're right, I should just set it outside of the loop. I'll edit the post.

If what you gave him suits his needs then that's good, hope I helped some.
In response to Kitsueki
You added in the spawn(), which I neglected, and used Crossed(); I'd say you were of some help here.

The OP isn't the most active, it'll be a little while before we find out what he found most helpful.
Yeah it seems to work fine thanks for the help
Best response
After having more problems pop up for him, Arch here asked for further help, I took a look and ran some test and came up with this:
obj/fire
icon='Dark.dmi'
density=0
New(loc, mob/m)
..()
spawn() m.fire(src)
for(var/mob/n in oview(0,m)) spawn() m.fire(src)
spawn(100) del src
Crossed(mob/m)
..()
spawn() m.fire(src)

mob
var/fire=0
proc/fire(obj/fire/o)
src<<"proc"
if(src.fire) return
src<<"Before While"
src.fire=1
var/TimesLoopedOnFire=1
FireLoop
while(o)
if(o.loc in locs)
src<<"Loop itteration #[TimesLoopedOnFire]."
TimesLoopedOnFire++
src.damage(10*TimesLoopedOnFire)
sleep(10)
else break
while(TimesLoopedOnFire)
for(var/obj/fire/f in oview(0,src))
o=f
src<<"Found to still be in fire, re-looping."
goto FireLoop
src<<"Second Loop itteration. Loops left: [TimesLoopedOnFire]."
TimesLoopedOnFire--
src.damage(10*TimesLoopedOnFire)
sleep(10)
src.fire=0
src<<"after while"
proc/damage(var/n as num)
hp-=min(n,hp)
src<<"gothere, damage=[n]."

He appears to have gone offline in the time it took me to test this properly, so hopefully he doesn't mind me posting this here.

[EDIT] Forgot the verb call:
mob/verb
Fire()
var/obj/fire/M = new (loc, src)