ID:716736
 
(See the best response by .screw.)

mob/proc/repair()
while((src.cloth>=1) && (src.maxcloth>src.cloth))
src.cloth+=10
sleep(20)

mob/Login()
if(usr.save==0)
var/tmp/A=input("Who is your character?") in list ("Seiya", "Shiryu", "Hyoga", "Shun", "Ikki")
if(A=="Seiya")
src.level=1 //level of the character
src.cloth=1000 //hit points of the character(cloth)
src.maxcloth=1000
src.cosmo=100 //the power of the character(attack)
src.arm=150 //cloth resistance of the user(defense)
src.speed=20 //speed of the character
src.maxspeed=20 //maximum speed of the character
src.stamina=100 //the total energy of the character
src.exp=10 //experience of the character
src.maxexp=20 //maximum experience of the character
src.stats=0 //points you can spend on these stats
src.luck=10 //luck(chance of dodging or a critical hit)
src.icon='seiya.dmi'
src.loc= locate(1,1,1)
src.repair(usr)
if(A=="Shiryu")
usr.arm=1000
usr.level=1
usr.exp=10
usr.maxexp=20
usr.maxspeed=10
usr.speed=10
usr.cosmo=100
usr.stats=0
usr.cloth=1000
usr.stamina=100
if(A=="Shun")
usr.arm=1000
usr.level=1
usr.exp=10
usr.maxexp=20
usr.speed=10
usr.cosmo=100
usr.stats=0
usr.cloth=1000
usr.stamina=100
else if(usr.save==1)
return ..()


I added src.repair(usr) under Seiya because it doesn't work under mob/New(). I am trying to have the cloth repair itself when the cloth variable below the maximum cloth variable of 1000. But it doesn't work! If I change around the while proc it will continue over 1000. So I think I either wrote the while wrong or the while proc just stops working indefinitely. Please help me fix this.
I am unsure if you can use double brackets ..

while(src.cloth>=1 && src.maxcloth>src.cloth)
still doesn't work
Best response
The while loop breaks because when src.repair() is called, src.maxcloth is not greater than src.cloth.

If you want a continuous loop, you can do the following:
mob/proc/repair()
while(1)
if((maxcloth > cloth) && cloth >= 1)
cloth = min(cloth + 10, maxcloth) // prevents cloth from going over maxcloth
sleep(20)
i thought loops never break? how do i not break it?
In response to TheDarkChakra
TheDarkChakra wrote:
i thought loops never break? how do i not break it?

Example: while(A)

With a while loop, while A is true, it will continue to loop through the statement. Once A becomes false, the while loop will break.

With while(1), 1 will always be true. Therefore, the only way to break such a loop is by using break or return.
where does 1 exist that makes it true?
One doesn't have to exist ... it is a number it is always true.

One is a lonely number
One can never have fun
When I met you
I thought I lost the blues
But now I find that I'm back in
That same old boat again.
One is an unhappy number
Why do you always make me wait
One and one makes two
That's why I need you
In response to TheDarkChakra
TheDarkChakra wrote:
where does 1 exist that makes it true?

1 = TRUE
0 = FALSE

With while(1), we are essentially doing while(TRUE). You need to be careful though, repair() will become a infinite loop. One player calling this procedure multiple times, or multiple players calling this procedure, could lead to a devastating decline in your games speed.
Thank you guys you have been very helpful that proc works.
Just keep in mind what .screw has said about repair() becoming an infinite loop because it will happen and may cause the game to crash...
but i have sleep in there. wont that save me?
Not necessarily. A loop is going to take up CPU time regardless of if it sleeps - putting a sleep in it just means that running the loop won't instantly lock up your game.

For example, if you had a loop that ran forever, and every time it ran it made an item in the game. That would eventually cause performance issues and a crash, right?

Just having a loop that increases a number every 20 ticks shouldn't be too much of a problem, though.
Still, if you can, it's better if you can find a way to do something without constantly checking the same value.