Spawning actor to penalize player when missed...

nerdster007

  • Posts: 10
Hello all,

Thank you in advance helping me get through this. I've been struggling for weeks on this issue. The logic is the same actor is spawned in one of several location, more than one at a time, if it's clicked then score is incremented by 1 and the actor is recycled (this is working fine). If it isn't clicked then every n seconds it checks to see if the game is paused, and if the actor was clicked (boolean). If the actor wasn't clicked, then it increments strikes (three strikes and you're out), and then it recycles self.

What actually ends up happening is that whether or not the actor is clicked strike increases. In fact, I'm pretty sure it continues increasing repeatedly from a single actor, and then the other actors as well.

I really appreciate the help here. I've tried several other solutions, but this is the most straight forward, and I feel like it should work. Thanks again.

Nate

nerdster007

  • Posts: 10
Sorry for attaching three of those screenshots. I'm tired and loopy from reworking the same problem for too long.

Hectate

  • *
  • Posts: 4643
Umn, could you check the attributes and tell me if you have two different attributes called Was Clicked? There appears to be one, "WasClicked" as a Boolean and another "Was Clicked" (notice the space) as a number?
:
:
Patience is a Virtue,
But Haste is my Life.
Proud member of the League of Idiotic Stencylers; doing things in Stencyl that probably shouldn't be done.

nerdster007

  • Posts: 10
Yeah, that was another method I used in case the local boolean wasn't working. It wasn't originally there though. And I'm still messing with this problem right now. It's been removed and the same thing is happening.

Thanks for checking though. I wish it were that simple.

Hectate

  • *
  • Posts: 4643
Hrm. Well first this would really be better as an actor behavior instead of events because then you can just attach it to any actor types and they all work equally the same - giving you ONE codebase to bugtest instead of three (or more).
OK, so reading the logic gets me this (ignoring actions on the part of the user for now).

Every N seconds:
IF ( Game not paused )
- IF ( WasClicked == False ) //using boolean version is important here for true/false
-- Set Strikes to Strikes + 1
-- Recycle Self

Should all be good, assuming WasClicked gets set to true/false correctly. So looking at that portion (first screenshot only)...

When Mouse is released on self
If ( Game not paused )
- Set WasClicked to True
- Recycle Self

...should all work as well. Perhaps try disabling those events and starting over with the barebones like that above.
:
:
Patience is a Virtue,
But Haste is my Life.
Proud member of the League of Idiotic Stencylers; doing things in Stencyl that probably shouldn't be done.

nerdster007

  • Posts: 10
Hectate, thanks for the tip. I'm using behaviors now to test on the actors (after disabling/deleting those events).

I tried out those barebones, as you said, and at least now I can see the problem more clearly:
As long as you are deleting the actor before that wasClicked == False loops starts, it's all good, but once the loop starts it continues every n seconds even when no new actor enters the screen. I don't understand why, and I'm not sure how to avoid or go around it. Any ideas?

Thank you so much for helping me, I hope I can finally resolve this issue...I've begun dreaming about it, which is a real nightmare, let me tell you.

nerdster007

  • Posts: 10
I've found a temporary fix, but it's not the ideal by any stretch:

In the every n seconds event
If (Game not paused)
-If (Was Clicked == False)
--Set Strikes to Strikes + 1
--Set Was Clicked to True
--Recycle Self

This interrupts the infinite loop that begins the moment the player misses the actor, but then the actor will stay on the screen for longer periods of time because somehow this timer that is attached to the actor is going on forever after the actor is deleted.

This is the problem, and no matter the solution it comes back to an infinite timer set from a single actor. If anyone knows a better solution to what I'm trying to accomplish, I really appreciate all help and feedback. Thanks again Hectate for helping me clarify the problem.

Hectate

  • *
  • Posts: 4643
Ah yes, good find. That was the key - your infinite timer. I had forgotten actually that the timer would continue on; once you start a timer it exists independent of whatever actor started it. Thus, you need to have the actor also stop the timer when it kills itself... happily there's a block for that!



So what you need to do is include a conditional check inside the timed task block. Put something like "If SELF is not alive; cancel" and it will shut itself off the next time if runs and discovers that the actor has been killed. That should do the trick.
:
:
Patience is a Virtue,
But Haste is my Life.
Proud member of the League of Idiotic Stencylers; doing things in Stencyl that probably shouldn't be done.

nerdster007

  • Posts: 10
Hectate,

Thank you so much! I'm glad to finally be heading in the direction to complete my game :).

As a note to anyone interested, I actually had to cancel the loop after it's completion
Every N seconds:
IF ( Game not paused )
- IF ( WasClicked == False ) //using boolean version is important here for true/false
-- Set Strikes to Strikes + 1
-- Recycle Self
- Cancel

This seems to be working. When I tried incorporating the check to see if self was alive, the timer would continue.

Thanks again for the help, I think the problem is resolved...Unless you foresee some terrible consequence from this method.