“Wait X seconds” and Timer problems

Hello.

I’m making a 2D top down game.
I’m trying to use “wait x seconds” actions and timers to manage enemy behavior using a finite machine state method. Both “wait” actions and timers invariably seem to fail.
It’s not obvious to me what I’m doing wrong.

INTENDED BEHAVIOR:
When hovering the mouse cursor over the object and pressing the ‘F’ button, the object should play an animation (dying), become inactive, then resurrect 3 or so seconds later, playing the appropriate animation.

WHAT HAPPENS:
Using no timers or wait actions, the enemy dies and resurrects immediately, which is expected and seem to be working on multiple instances, a positive sign.

However, as soon as add a timer or wait actions, the enemies “break”, staying in place, playing the wrong animation, etc.

USING A TIMER:
Using a timer causes multiple instances of the enemy to break.

Gif:
timer

Events:

USING WAIT ACTION:
Using wait actions causes almost the same issue with very subtle differences.

Gif:
wait

Events:

Why does this happen? I’ve read the page on timers and such, would a “fake” timer using variables solve this problem? The issue is clearly the timers, as the enemies do what is intended by the events (resurrect).

Without any timers or action events:
no timers

As you can see, the problem is not as pronounced here and would happen only in extreme edge cases during gameplay.

I see nowhere action to check if cursor is on knights neither i see any that checks if cursor is not on them
You show part of your logic which you assume is cause of issue without showing the part that actually affects the logic

Without showing anything more
I think your issue can be fixed by just checking if animation is NOT something
You are checking if animation is something to add way
Like is it Reassembling or Disassembling
Yet no where you are ensuring that during other logic you have there
You are not checking if animation is not equal or inverting condition of checking if animation is Reassembling or Disassembling

You noticed you have same issues with wait as you have with timers
Believing variable would change anything kinda makes no sense
Your problem is not with counting anything
Your problem is with that you are allowing stuff to happen without restricting it

If you want to try counting by variable
You can set some variable to 3 and in separate event subtract from it 1 * TimeDelta()
This is how you are subtracting 1 each second from var if your game runs at 60 fps

So in conclusion
image
This 1st event could use condition like
Animation of enemy dark armor is not equal to Disassembling
Or maybe i am wrong and some other event could use it
You should try for example add there something like idk let’s say space key is pressed
And now you have full debug control over when is something happening
And you can test if it is properly blocking something when you want it to be blocked
Test it

Hi!
Thanks for chiming in. I eventually managed to partially solve the problem by adding a “dead” animation that lasts a few seconds.
Still, I’ll try your suggestion in the old event sheets (I kept it as a copy so I could post it now), and if it works, that’s better, better than the animation “hack”.

Full event sheet:



Also: I’m creating another enemy and running into the same problem. Timers and wait actions simply don’t seem to work as a user would expect.
I have tried several modifications.
All of them result in a different type of failure.
Sometimes only one instance works, as if hogging the timers/wait actions for itself and leaving the other instances broken.
Sometimes all instances get stuck in one state, or even behaving as if between two states.
I’m now trying to use a wait action, and the enemies seem to switch back and forth between states (chasing and attacking) at intervals not specified in the wait action (1 seconds). They’re flipping between states just as the armor did.

Example, with colors (green is chasing, red is attacking):
summoner problem

Full events sheet for the summoner enemy:


I did not go fully trough your events i just checked them for what potentially could be issue here

Now you have a choice
Follow what i say and come back here with your next issue which you will most likely have soon
Or listen to what i say but also try to understand how i deduced that and start learning to understand it yourself

Kinda fish a fishing rod situation
You can come here for fish and you will get it but you will come back here each time you get hungry
Or you can come here for fishing rod and fish whenever you want without needing help of others

Check this out

Remember this
For each object type event
DO NOT LIKE trigger once or to say it correctly trigger once do not work with it

I wrote above so you don’t try to shove in there trigger once

Now what we see here is IF there are less than 11 enemies on scene
Then you are constantly spamming wait for 1 sec
So you are each frame ordering your game to wait 1 sec then change state
So each frame after that 1 sec you are updating that var for enemy

You should create variable for enemies you check as some sort of fake trigger once
For example you could add to this event
Enemy variable CanAttack is false
In action
Set enemy variable CanAttack to true
Wait 1 sec
Change var state of enemy set to attacking

This way as long as you don’t set CanAttack var back to false
This event won’t kick in again

I have no idea if it will fix your issue if not just reply to me your issue is still there
But i wrote it so you can start looking at events and try to understand what will happen just by reading them

It took me awhile to get hang of it and i was feeling lost when i first did try to do it so you most likely will also
But just like me you need to start somewhere
You need to start understanding what you are doing

BTW i just noticed

So turns out here if its attacking you are changing it chasing
BUUUT looking at what i wrote below previous image
You should deduce it switches to chasing then instantly switches back to attacking again
And now to chasing and so you created loop that spams both logic

Really try to look into your events
And read them while trying to understand them
It will help you A LOT
Where do not expect to understand everything right from the start
I am over 2 years here and i don’t understand my events sometimes
No shame in that

Just give it a try

1 Like

Your suggestion using booleans has worked.

Events changed:

Gif:
summoner problem (solved) 3

Now you have a choice
Follow what i say and come back here with your next issue which you will most likely have soon
Or listen to what i say but also try to understand how i deduced that and start learning to understand it yourself
Kinda fish a fishing rod situation
You can come here for fish and you will get it but you will come back here each time you get hungry
Or you can come here for fishing rod and fish whenever you want without needing help of others

I appreciate your advice and understand where it comes from.
By default I try to understand the events and create them correctly, and if they don’t work even if they logically make sense, I go through a lengthy process of trial and error.
If that fails, I search the forum, and if that doesn’t yield useful results, I ask for help as a last resort, as to not make people waste their time and also increase the likelihood of being further helped in the future (no one wants to help someone that doesn’t put in the effort or needs it constantly).
The big issue for me is, often times, reading the events in the order in which they’ll happen, they seem to make sense, but upon execution don’t, due to obscure details such as:

For each object type event
DO NOT LIKE trigger once or to say it correctly trigger once do not work with it

This is one of, if not the major issue I’ve been having with this engine.
The unspoken, hidden, subtle caveats one only encounters when trying to do something a little more complex than the basics.
Every platform has its own subtleties, but this gets a little more frustrating when it happens in one that presents itself as easy to use.
Syntactically speaking, there’s no reason a “Trigger once” shouldn’t work there. It logically follows if you read the events.
Until you find out it doesn’t.
I’ve lost count of how many times I have thought to myself that maybe it would be easier to learn to code because of issues like this.

So what ends up happening is I may not trust what the event does what it says it does, and may try events or “hacks” that don’t seem to make sense (namely, using a 1 frame animation that lasts 3 seconds because timers/wait actions are unreliable, or using “for every object” events even if they may not seem needed, for instance).
I’ve become extremely wary of using timers and wait actions for this reason, they simply don’t work as intended, at least not for multiple instances.
Now I have learned “Trigger once” doesn’t work with “for each object” type events.
Every enemy or mechanic I make seems like one big box of surprises and uncertainties.

I apologize if my commentary is acidic, it’s not directed at anyone in particular and is just an expression of my frustration in these past few days in general.
I appreciate your help immensely, more than I can put in written form, because seeing those little guys on the screen finally work seem absolutely miraculous.
It really shows your experience and the long road I still have ahead.
Thank you so much.
:pray:

1 Like

If you believe ppl that are here for 5 years don’t have moments of frustration and not having idea why somethings is happening when it should not
Then you BS yourself

We all experience that no matter how long we are here
And only tip i can give you
You should try to deduce for few mins wtf is going on
Then if that fail not try to follow events by order but check what is causing something to happen
In your case printing object variable to text when you hover cursor over your enemy object
Would tell you that this var is constantly switching back an forth
So you now only would need to find event that switches is back
And you could deduce yourself that for each event is triggering it constantly due you spam wait action without fake trigger once

I wasted tons of hours before i learned to check what is actually going on
Now i am wasting only minutes before i can fix my junk myself

Try it next time
You can be amazed how easy it becomes to pinpoint the problem once you see when and what is happening

BTW printing variables to text is your best weapon
BUUUUUUUUT also useful things in your arsenal are
Tinting object color so you visually see that something happen
For example object variable = attacking tint object to red
Object variable = chasing tint object to blue or green
You would instantly see it spams

And my favorite
Play sound action
Nothing helps you fix your issues as annoying sound spam each frame
Try it i bet you will like it as much as i do

1 Like