ID:179970
 
How can I stop the "Maximum Recursion level reached" error from happening? I know this isn't very clear, so I will post my coding.
New()
spawn(10)
growth()
proc
Size_check()
sleep(5)
switch (size)
if (1) icon_state = "Level1"
if (2) icon_state = "Level2"
if (3) icon_state = "Level3"
if (4) icon_state = "Level4"
if (5) icon_state = "Level5"
sleep(5)
growth()
growth()
sleep (dr)
pop += 1
gc += (income)
Size_Inc()
Size_Inc()
sleep(5)
switch (pop)
if (50)
size = 2
income += 1
if (100)
size = 3
income += 1
if (200)
size = 4 income += 1
if (400)
size = 5
income += 1
sleep (5)
Size_check()
Deadlocke wrote:
How can I stop the "Maximum Recursion level reached" error from happening? I know this isn't very clear, so I will post my coding.
New()
spawn(10)
growth()
proc
Size_check()
sleep(5)
switch (size)
if (1) icon_state = "Level1"
if (2) icon_state = "Level2"
if (3) icon_state = "Level3"
if (4) icon_state = "Level4"
if (5) icon_state = "Level5"
sleep(5)
growth()
growth()
sleep (dr)
pop += 1
gc += (income)
Size_Inc()
Size_Inc()
sleep(5)
switch (pop)
if (50)
size = 2
income += 1
if (100)
size = 3
income += 1
if (200)
size = 4 income += 1
if (400)
size = 5
income += 1
sleep (5)
Size_check()


Do you have any idea how to do a if statement?

if(400)
this tell the if statement nothing

if(src.Health>=400)
this checks to see if it is over 400

take that as a example.
In response to Nadrew
Well I am using the switch statement, so I dun think I need to say (src.health>=100). If this is wrong please correct me
In response to Deadlocke
Deadlocke wrote:
Well I am using the switch statement, so I dun think I need to say (src.health>=100). If this is wrong please correct me

Nope, your use was fine.

(Geez, Nadrew.)
Deadlocke wrote:
How can I stop the "Maximum Recursion level reached" error from happening? I know this isn't very clear, so I will post my coding.
New()
spawn(10)
growth()
proc
Size_check()
sleep(5)
switch (size)
if (1) icon_state = "Level1"
if (2) icon_state = "Level2"
if (3) icon_state = "Level3"
if (4) icon_state = "Level4"
if (5) icon_state = "Level5"
sleep(5)
growth()
growth()
sleep (dr)
pop += 1
gc += (income)
Size_Inc()
Size_Inc()
sleep(5)
switch (pop)
if (50)
size = 2
income += 1
if (100)
size = 3
income += 1
if (200)
size = 4 income += 1
if (400)
size = 5
income += 1
sleep (5)
Size_check()

Let's observe what process you're doing here:

Spawn growth() after I'm created:

growth() runs Size_Inc().
Size_Inc() runs Size_check().
Size_check() runs growth().

Now, look at that closely. There's an infinite loop! I can tell you want a loop; but the key issue here is that in BYOND terms, it will only run one proc at a time. The sleep() proc is a special proc that continues to run this proc for that amount of time. Thus, until BYOND gives up, this proc will run itself indefinitely, halting all other procedures in the process.

What you need to do to fix it is make it so that Size_check() does NOT call growth. Instead, you need to make code that uses the spawn() procedure (since spawn() does not halt execution of other procs) to run the code every so often. Make your code run similarly to this:

obj/whatever
New()
spawn(10) GrowthLoop()

proc
GrowthLoop()
spawn(dr)
growth()
GrowthLoop()

growth()
pop += 1
gc += (income)
//sleep(5)
Size_Inc()

Size_Inc()
//sleep(5)
switch (pop)
if (50)
size = 2
income += 1
if (100)
size = 3
income += 1
if (200)
size = 4 income += 1
if (400)
size = 5
income += 1
//sleep(5)
Size_check()

Size_check()
//sleep(5)
switch (size)
if (1) icon_state = "Level1"
if (2) icon_state = "Level2"
if (3) icon_state = "Level3"
if (4) icon_state = "Level4"
if (5) icon_state = "Level5"
//sleep(5)

The changes I made were the following:
1) I arranged the procs in order that they were called.
2) I created a new proc, GrowthLoop(), which runs growth(). This will run itself periodically, according to the dr variable that you had.
3) I removed all delays. You might want to re-implement them, but I see no need.
4) I prevent Size_check() from running growth() over again.
In response to Spuzzum
Spuzzum wrote:
Deadlocke wrote:
Well I am using the switch statement, so I dun think I need to say (src.health>=100). If this is wrong please correct me

Nope, your use was fine.

(Geez, Nadrew.)


Sorry! Yesterday was a long hard day and it was late and I was tired (Note to self:Stop replying when tired)
In response to Spuzzum
Yes, thank you for that Insight. That might prove very usefull. I will write that down. Thanks Spuzzum