ID:144571
 
I've tracked the problem down to this proc. The Infinite loop is strange.
            proc/powering()
while(active)
for(var/obj/electrionics/battery/b)
if(b.power<=0)
usr <<"Battery Depleted"
active=0
else
b.power-=100
power+=100
sleep(30)


uh, you dont actualy have anything in the while...
and you dont have anywhere for that for check to look
ie: for(stuff in world)
Assuming that it's not like that in your code (I'm geussing that it didn't copy/paste correctly), there may not be any battery objs in the world. I suggest doing some safety check the loop like this:
proc/powering()
var/obj/electronics/batter/b //Just have to do this to check for it in the world
while(active && b in world) //And since b is already defnined, no point in redefining it
for(b in world)
if(b.power <= 0)
usr << "Battery Depleted"
active = !active //This appears to be a boolean var, so doing this will
//simply set it to a true value if it's false, and vice-verse
else
b.power -= 100
power += 100
sleep(30)
In response to Popisfizzy
I made a little mistake i forgot to add something

            proc/powering()
while(active)
for(var/obj/electrionics/battery/b in contents)
if(b.power<=0)
usr <<"Battery Depleted"
active=0
else
b.power-=100
power+=100
sleep(30)
In response to Yorae
mob/proc/powering()
var/active=1
while(active)
active=0
for(var/obj/electrionics/battery/b in src.contents)
if(b.power<=0)
src<<"Battery Depleted"
else
active=1
b.power-=100
power+=100
sleep(30)

id try something more like that!
it always unsets active even if there arent objects, and then turns it back on if the power is over 0, also i set src.contents and made it a mob/proc, im assuming u already had it as a mob proc... but just incase lol
There are quite a few problems with this code, and I'm surprised that no one has pointed them out to you.

  • Your while loop, because it has nothing indented under it, will by default do nothing and continue to loop over while active is true, which isn't happening in the foreseeable future.
  • You have usr abuse in there.
  • You're not taking into consideration that the battery might not have at least 100 power, which brings upon whole other variable just to make it remain decent looking.
  • You're spamming the user with "Battery Depleted" messages. Consider the following: You could just handle this and your other design problem with setting active to 0 if one battery is depleted by creating two new variables: depleted and batteryCount.

    Set up a do...while loop, with the condition as it is now. Then you place your for loop in there, incrementing batteryCount each time and doing nothing but incrementing depleted if b.power is <= 0. Then, after the for loop ends, you can output a nice "[depleted] out of [batteryCount] batteries depleted" message. Then, if depleted >= batteryCount and this object doesn't have the power it needs to run, then we can set active to 0 and successfully end the while loop. You'll just need to set the batteryCount back to 0 at the end of the loop.
In response to Audeuro
Audeuro wrote:
There are quite a few problems with this code, and I'm surprised that no one has pointed them out to you.

no one has pointed them out? i recoded it and fixed those things and pointed them out o.O
In response to Falacy
Theres a problem with the code you posted it just doesn't generate the power anymore mine did but had the loop problem.

Edit: I've tried many diffrent ways but the problem is that is doesn't give power at all or it just gives me the infinite loop any other ideas?
In response to Falacy
Nice recent edit. At the time of posting, your code still have 3/4 of those mistake and added in another one. The design in your "rewrite" of the code is still not really sufficient enough.
In response to Audeuro
I was talking about Falacys code its more or less the same as one of my attempts what am i doing wrong.