ID:264503
 
Code:
    proc/timeloop()
while(src)
src.seconds++
var/text
if(!text) text=seconds //this is just for the first iteration of the loop
//however it keeps getting turned back into seconds
var/minutes
if(seconds==60)
minutes++
seconds=0
seconds=time2text(seconds, ":ss")
text="[minutes][seconds]" //rewrite text to read as 1:00 (for example)
//but that only happens for one iteration of the loop, why?
world<<"Timer: [text]"
else world<<"Timer: [text]"
sleep(10)


Problem description:
It should only change text to equal timer if text is null... why is it doing that each time?

To explain, each time 1:00 appears, the loop immediate goes back to outputting 1, 2, etc. Why?

You're defining "text" inside of the while loop, so everytime the loop finishes running the statement, and goes to run it again, the text variable is discarded, and then redefined (and so is back to a null value).

You need to change the scope of the text variable so that it exists outside of the loop. Just define it before the while(src).

There are also some other problems, where you keep switching seconds between being a number and text.

Try this:
    proc/timeloop()
var/text="[seconds]"
if(seconds<10) text="0[text]"
text="0:[text]"
var/minutes=0
for()
seconds++
if(seconds>=60)
minutes++
seconds-=60
text="[seconds]"
if(seconds<10) text="0[text]"
text="[minutes]:[text]"
world<<"Timer: [text]"
sleep(10)


I assume you have seconds defined elsewhere? Any particular reason for that?
In response to DarkCampainger
You aught to put that sleep() at the beginning of the loop, otherwise you lose your first second. You could probably steamline the proc so it's easier to read if it looked more like this:
proc
timeloop()
var
seconds=0
minutes=0
output=""
while(1)
sleep(10)
seconds++
if(seconds>=60)
seconds-=60
minutes++
if(seconds<10)output="0[seconds]"
else output=seconds
world<<"Timer: [minutes]:[output]"
In response to SuperAntx
Alternatively:

proc/timeloop()
var/seconds = 0
var/minutes = 0
do
for(seconds = 0 to 60)
world << "[minutes?("[minutes]:"):""][round(seconds/10)][seconds%10]"
sleep(10)
while(++minutes)


But an important question here is, "do you actually need to be doing this"?
In response to Garthor
Garthor wrote:
But an important question here is, "do you actually need to be doing this"?

Judging from Vic's post it would be easier for him to follow and learn from. So in a way, yes.