ID:166980
 
Could anyone point me out to the signs of an infinite loop? Examples? I have one in my game, and when I leave it up overnight it is breaking. I am pretty sure it's somewhere in the timer, made by Hiead. If you guys could do me a favor and look it over that would be nice. (I came to this conclusion because I had added this in, and it started inifnite looping. I also added it to Snake Pit, and it started infinite looping.)

var
timestart = 0
s = 120
proc/GetTimeString(s=0 as num)
s = (s>356400 ? 356400 : s)
var
m = 0
h = 0
m = round(s/60)
s -= m*60
h = round(m/60)
m -= h*60
return ((m>=10 ? "[m]" : "[m]") + \
":" + (s>=10 ? "[s]" : "0[s]"))

proc/GetTimeString2(s=0 as num)
s = (s>356400 ? 356400 : s)
var
m = 0
h = 0
m = round(s/60)
s -= m*60
h = round(m/60)
m -= h*60
return ((h>=10 ? "[h]" : "0[h]") + ":" + (m>=10 ? "[m]" : "0[m]") + \
":" + (s>=10 ? "[s]" : "0[s]"))

mob
var/testing = 0 // Can't run 2 timers at once!
proc

ClearClock()
if(!client)
return 0
for(var/obj/Number/N in client.screen)
del N

DrawClock(time, startx = 15 as num, starty = 1 as num, xoffset = 4 as num, yoffset = 4 as num)
if(!client)
return 0
if(isnum(time))
time=num2text(time)
if(time)
ClearClock()
var/offset = xoffset
var/xpos = startx
for(var/i=1,i<=length(time),i++)
var/char = copytext(time,i,i+1)
new/obj/Number(client,char,"[xpos]:[offset],[starty]:[yoffset]")
offset += (char_widths[char] ? char_widths[char] : default_width) + char_distance
while(offset > 32)
offset -= 32
xpos++


obj/Number
icon = 'numbers.dmi'
New(client/C, char, s_l="1,1")
..()
icon_state = char
screen_loc = s_l
C.screen+=src

var
default_width = 6 // Default number width. (in pixels)
char_widths[] = list("1"=1,":"=1) // For alternative widths. (like the number "1" is 1 pixel wide)
char_distance = 7 // Pixels between numbers.

mob
var
os = 0
proc
Tick()
if(s<=0||!timestart||!currentartist)
TimeOver()
return
for(var/mob/M in world)
if(!M.client) continue
else
M.os = s
M.DrawClock(GetTimeString(M.os))
sleep(10)
s--
if(s == 30)
var/txt
txt = "[copytext(word,1,3)]"
var/new_text = "[txt]"
var/i = length(word)-2 // the amount of underscores to add
while(i --)
new_text += " _"
world << "<span class=game>Hint: [new_text]</span>"
Tick()
TimeOver()
if(currentartist && timestart)
End(null)
s = 120
for(var/mob/M in world)
M.os = s
M.DrawClock(GetTimeString(M.os))
timestart=0
return
TimeLimit()
if(timestart) return
timestart=1
s=120
Tick()



Thanks for any help provided. Also I posted this in Developer How-To because I really don't know if the problem is there, or somewhere else. So I rather just ask for signs of infinite loops, and look through my code to see whats up.


-Doh
I believe your problem is that tick is not being spawned, so after running for a while the call stack builds up and gives you an error.
In response to DarkCampainger
So to fix it I should do

spawn(1)
Tick() ? At the end of the Tick() proc? I am not really familiar with spawn thats why I often screw up with it. Thanks for the answer.

I really have no way of testing the fix, I guess I will just have to wait over night.

-Doh
In response to XxDohxX
XxDohxX wrote:
So to fix it I should do

spawn(1)
Tick() ? At the end of the Tick() proc? I am not really familiar with spawn thats why I often screw up with it. Thanks for the answer.

I really have no way of testing the fix, I guess I will just have to wait over night.

-Doh

Yea, but just put spawn(), or else the clock will .1 seconds slow. If you want to make a faster test, you could change the sleep(10) to sleep(1), then it would take 1/10 of the time to get to the breaking point. But to do this, I suggest you leave the spawn out first, time it when the sleep is set to 1, and then put the spawn in and wait until the same amount of time (Give or take a bit) to see if it gives the error.
In response to DarkCampainger
I will edit this post later when I can test it out. Thanks alot.

-Doh