#Infinate loop until death, unable to work out why

1 messages Β· Page 1 of 1 (latest)

weak forge
#

Hey, having a really dumb issue with my code which can cause a large memory leak with it looping so much. Essentially the logic is:

  • Timer hits 0
  • Stop timer and trigger the attacker script
  • Checks if the barricade is active
  • If yes, decrease it's health by 1. If no, kill player
  • Restart timer

However on step 4, it's just looping back to step 2 for seemingly 0 reason and will keep looping through until the barricade has been broken and the player dies. I've been trying to debug this all night, breakpoints just seem to baffle me even more as it's seemingly just, flipping values by itself and ignoring my if statements. I'm sure it's just something incredibly simple but I can't work it out. (I'll attach the relevent scripts after this message)

#

The debug logs from 1 play

trim barn
#

Please check out #854851968446365696 to find places where you can post large amounts of code. Very hard to read that much in tiny window here πŸ˜… then we'll help you mate

weak forge
#

I mean, those are the uploaded files?

#

if you hit that it'll show it all, and it's got the coloured syntax

trim barn
#

It is the guidelines and making it easier by allowing chatting while looking at code

trim barn
#

Ok so trying to get an idea of the intended logic here.

Timer.cs is responsible for controlling the attacks of the attacker on a timer.

The AttackerScript.cs is responsible for dealing damage to the barricade. And triggering the destruction of barricade if health of barricade is equal to or 0.

For BarricadeScript.cs, it will no longer stay active when broken

#

Is this the intended flow of things?

weak forge
#

Yeah

#

in my first message that's the intended flow

trim barn
#

And then when timer reaches 0, it will just keep looping the "AttackerGo" method. That is the problem you're having?

weak forge
#

Yeah basically

#

you can see from the debug logs that it'll "stop" the timer over and over, so it's not just that one script looping either

trim barn
#

Ok so quick question, "targetTime" in the timer.cs class. Is this meant as a sort of "wait period" before the attack starts attacking with 3 seconds interval, as seen in the "waitforseconds" coroutine?

weak forge
#

So essentially after 10 seconds, the attacker will attack. So that's what that timer is

#

The timer is then "paused" at 0 until the attacker logic is finished, then it restarts back to 10 again and does it all again

trim barn
#

And where is it reset to 10 seconds again?

weak forge
#

omfg

trim barn
#

there you go

weak forge
#

I am so incredibly dumb lmaoo

trim barn
#

dont worry, it's very normal to get lost and forget small things while trying to come up with a great solution

weak forge
#

Yeah I was so caught on the loop part I didn't even think to check that side of it aha

#

Thank you so much. Now to work out where I can put the reset aha

trim barn
#

No problem! Glad you can move on

weak forge
#

And with that fixed, the prototype is finished πŸ˜„ Working absolutely perfectly now, thank you again ever so much!

trim barn
#

Great to hear πŸ™‚ Would love to see the result!