ID:844603
 
Keywords: second, time, values
(See the best response by Kaiochao.)
Problem description: I've looked mostly everywhere I could think of, and I can't seem to find the code that lets me add values per second, or just in any unit of time really. What I want the verb to be able to do is increase a variable by a set amount every set amount of seconds. Anyone know how to do this?

IE. I hit the meditate verb and want my spirit to go up rand(0,20) every 2 seconds. Without continuously hitting the meditate verb. Sorry if I come across as vague.

while(condition) // is true
variable += increase
sleep(seconds * 10) // measured in 1/10ths of a second

This is one of your most basic looping statements, I'd say.
When you do this, it will keep repeating the code for as long as the condition is met. Of course, this means code after it will not be run until the loop breaks.
In response to Kaiochao
    mob/verb
Meditate()
var/meditating = 1
while(meditating) // is true
spi += rand(0,20)
sleep(3 * 10) // measured in 1/10ths of a second


I tested that and it gave me a message about infinite looping... Any ideas on how to dodge that?
In response to Killalongjohns
Best response
Don't you see a difference between our code? Tabs matter.
proc
// Begin 'proc' code block
Blah()
// Begin 'Blah' code block
statement
while(condition)
// Begin 'while' code block
statement
// End 'while' code block
statement
// End 'Blah' code block
Blah2()
// Begin 'Blah2' code block
statement
// End 'Blah2' code block
// End 'proc' code block

Only statements in the while()'s code block will be affected by the while(). You need to indent.

The reason you're getting an infinite loop is because your delay isn't under the while(). Also, you never stop meditating.
Ahhh ok! I definitely understand now. Thanks for the clarification, as I said I'm new to this but hopefully I'll catch on quick :). I used

Meditate()
var/meditating = 1
while(meditating) // is true
spi += rand(0,20)
sleep(3 * 10) // measured in 1/10ths of a second
and it seemed to work. Thanks again
Nice one. Infinite loop.
Be sure to have a filter for this in atom/moveable() (or, wherever you want really)
if(meditating)
!meditating

//When an atom moves while meditating, he will stop.

That was helpful too :D thanks Tafe. I didn't even know how fun coding was up until now