Trigger once per object

I’m losing my mind on this one. I have searched for all the posts on this one but i can’t find a solution to my predicament.
I want the enemy to flash white when hit. I want to avoid new animations with white sprites.
The enemies spawn infinitely as the game progresses. I have the “Flash to effect” behavior triggering the “Adjustment” effect.
I can’t disable the effect by default so I have to disable it with an action but i don’t know how to make this action only work once per object, because otherwise the constant check for disabling the effect interferes when it should trigger.

I’ve seen recommendations on attaching a boolean variable to make the “Trigger once” into triggering again but then it goes back into triggering more than once to the same Enemy.
I thought “for each instance of Enemy” would do the job but it doesn’t. Attaching a “Repeat 1 Time” to that also doesn’t do it.
What options do I have?

first time i’ve eard about this problem…if u have this…

Cattura

then it should works when …
for each object enemy,collision event,trgger once-------make flash.

mostly depends on your hitcheck events.

better if u can post your events

I am over 2 years here
I did once ask for it but i was told it is not possible
So i was asking any1 who pasted in gdevelop wip channel on discord ANY video showing his enemies/players flashing white
ALWAYS i was told it was made bu having duplicate sprite which was totally white
And that was never a solution for me i needed it as effect
BUT there was no effect for it or at least i did not know about it
On other hand i only tested outline but whatever

SOOO
Thank you very much for it cause it opens A LOT of new ways of making indication of damage inflicted NOT with tinting something to red or black

So enjoy

2 Likes

For the record, the “Make object flash” action in @RMDB’s screen snip is from the Flash Object extension:

Replying to @RMDB this is what I have

What you suggested makes you blink visible to invisible, i want it flashing white.
Googling “Gdevelop trigger once per object” or “…once per instance” you get 5 posts about this.

@ZeroX4 That’s clever and simple! Using opacity to prevent the “no” effect from disabling the flash. I need to try that

That is variable
Variables are not only well variables
But just some values that vary
I could make variable call it Checker check if its 0 and if so set it to 1

If my object is 20 pixels wide i could check if object.Width() = 20
If so change it to 20.01

And in all these cases it would work exactly the same

@RMDB Flash extension is for opacity or show/hide

then zero method will surely works…however…
…to me it looks like something is wrong with your timer event

@zero…yep i didn’t get he wanted static flash

@ZeroX4 Works amazingly, thanks, m8. I’ve been banging my head for 4 hours on this and this solution is so simple. Adjusting the flash behavior or the wait timer I can change the number and period of flashes.

@RMDB I think it does too but it appears to be working as intended so far. Sprite activates every 2 seconds and applies damage in only one frame even though the collision lasts 3 frames

1 Like

I’m not like others that can test things on the fly…but as far as i know…subevents happens after the parent actions…
so if you say… if timer >= 2 reset timer…i’m not totally sure that the subevent (that require the timer to be>=2) happen…
anyway glad it worked…but i would pin that events group for later…

…also be wary about the async timer…

Oh, that’s because the line to start the timer is not in the image. It’s way up there in the list of events and I was too lazy to go fetch it, sorry. My events list is a nightmare. I don’t have groups yet. I’m experimenting with all the things. enabling and disabling chunks.
Rather than finding roadblocks every so often as I build the game, I’m thinking of all the mechanics and finding all the roadblocks at the same time to see if I can do what I want, I guess as way to not waste my time if i’m not capable of achieving it… I’m just surprised the enemy flashing was a roadblock to begin with.

async timer?

wait action is an asynchronous timer…
if u say wait 1 sec to change opacity, it could happen that the next time your event trigger, the timer is still running and your action may not happen.

Async means
That if you make event like
Left button clicked
Wait 1 sec
Fire bullet from pistol

THEN
As many times as you click LMB that many times in needs to fire
Just each time you gonna click it it will wait 1 sec before it does

For example imagine you will click LMB very fast 3 times
Each click does not cancel previous click
So instead of resetting timer here
You are adding to cue some actions

Look at it this way
When you go to youtube
And you click 0 on video 3 times
You will reset it 3 times to beginning of it

This is how it would work with timers

With WAIT action
Pressing 0 key 3 times
Would make your video play 3 times from start with intervals in which you pressed that 0 key 3 times
That is async

Anyway i just wanna say it again
I am over 2 years here i was always told changing color to white is not possible since you can only tint it to darker colors or just add colors
And now turns out it is fairly simple

IDK why i never went trough all effects to check them but whatever

I AM THE ONE that walks away from this post more as a winner than you trust me

Where at the same time i am happy your problem is solved

BUT that said i am feeling RMDB is right here
Maybe your events work and do what you want
However i feel like it be simplified
And streamlined

For example imagine this you have timer you check if its above 2 sec
Then you reset it
Then if it was and enemy was in collision with bite you wait 1 sec

SOOOOOOOOOOOO
Why not check if timer is above 2 sec
And do something you need

Then if timer is above 3 sec flash your object and THEN reset timer?
And so you can gtfo with WAIT action

That is just a example

I think if you describe exactly step by step what you want to happen and when
We could come up with better way to do it

BUT if what you have works for you flawlessly and you are happy with it
IDK if it would make sense to mess with it
So choice is yours

1 Like

Hey, as a guy that dove head first into game development 2 weeks ago without knowing jack and struggles to comprehend programming logic (even Gdevelop event logic), Im more than happy that i gave a more experienced person an eureka moment, m8.

What i have here is a melee auto attack in the form of an animated sprite that triggers every X amount of time, in this case 2 seconds.
The attack rotates around the player (topdown game) and follows the cursor (this part is accomplished).
It’s supposed to have no button to trigger. It auto attacks from the moment the level starts till the end. The flash triggers on the enemy when a collision between it and the attack happen.

The timer resets the animation so that i have a better control of the attack speed and also prevents the collision box from doing damage every frame. Only doing damage at 2 second intervals.
What i want to add afterwards are buffs that increase the speed of attack, maybe burst of attacks and/or increase sprite size for larger collision area.
I will also want to configure so in a click of a button the cursor aim switches to auto aim to closest target.
If any of these plans interfere to how i’ve set up the current event please do let me know.
Cheers for the help and the same time you’re more than welcome @ZeroX4

1 Like

In my country ppl say
When everybody says something is impossible
You need to wait for someone who don’t know something is impossible
And just do it
I could just check all effects even worse it was very first effect my god
BUT whatever we both got now what we want

Anyway
1st condition you see is called Compare Two Numbers
That is how you gonna find it using search bar
Right from time from start you see ,2
That 2 is your timer you change it to (),1.4 it will trigger every 1.4 sec
Instead you can make variable called Speed and do
mod(TimeFromStart(),Speed)
And now you can adjust that speed via events
For example when player level up or when you click on upgrade button
You subtract from Speed variable 0.2 and now instead of 2 you will have 1.8
You subtract another 0.2 and now you have Speed with value 1.6
And that is how you deal with upgrades
Same goes for size you change scale you can set some variable to 1 and then change your bite scale to that variable and manipulate that variable

Basically EVERYWHERE you see number anywhere in events
You can replace it with number variable and manipulate it on the fly via events or whatever

1 Like

I’ll to check that when i get home but that is quite confusing. “TimeFromStart” i assume it’s THE timer and not calling for a timer event named “TimeFromStart”? So everytime 2 seconds elapse then the sprite activates? Wouldn’t the Trigger once make that happen only once? The attack sprite is not set to loop.

IIRC, In that configuration the attack would damage the enemy multiple times. With my timer it will only deal damage once per enemy. The collision box lasts 3 frames, it allows more mobs to enter the damage area and take damage but only once per.

On the 3rd event i don’t know why the condition for no collision or the opacity action to 255 is required.

I don’t know why the 4th event is required if i can place the action of the 4th event after the change opacity to 254 in the 5th event

I tried it and it works flawlessly. I did remove the trigger once though. Why does it work? I’m still wrapping my head around it. Many Thanks, m8

But now I have a follow up question: during the level, more weapons will be acquired, they will also auto attack with their own timings. What expression can I use for such weapons. Definitely can’t use TimeFromStart? Or can I?

I was replying to your previous message few hours ago but a lot had happen in real life and i had to dump it
And i see you kind got it but you made one huge mistake
You are checking time from start less than <
Where you should be checking greater than >
That is why it is working for you which will not work soon

Basically look time from start is a timer that runs with your game
It is not a timer you can stop or start it will just run on its own with each of your scenes

So you can only check its time by referencing it with TimeFromStart()
So TimeFromStart() will return in seconds how long your scene is running

NOW
mod( NumberA , NumberB ) works like this

Take NumberA and loop it around whatever i put in NumberB

So you have TimeFromStart() it will go from 0 1 2 3 4 … to infinity

But you don’t want that you want to loop it to go 0 1 2 3 4 5 0 1 2 3 4 5 0 1 2 3 4 5 and so from 0 to 5 which means it will loop 6 digits cause 0 is also accounted for

Then you write mod(TimeFromStart(),6)
And you get that
It will go from 0 to 5 and then reset to 0 and go again to 5

How about mod(TimeFromStart(),60)
Isn’t that just counting 60 secs over and over? like have we made a timer?
Well guess what you can make timer for mins hours day seconds ANYTHING you want out of it

Imagine this
You have some value that goes

0 1 2 3 4 5 6 7 8 9

You wanna loop it to 3
so mod(SomeValue,3)
And now you will get
0 1 2 0 1 2 01 2 0 < GET from mod
0 1 2 3 4 5 6 7 8 9 < SomeValue

Now that you get the idea
YES you can re use TimeFromStart in different event
But you are NOT modifying it
You are only checking its state or modified state to be precise

So mod(TimeFromStart(),2) is looping around 0 1 0 1 0 1 0 1
So it is 2 secs
And magic here comes from that condition
Compare two numbers
Check if mod(TimeFromStart(),2)
Is greater than 0,01

And that is because (i mean why its not 0)
Cause for it to work with trigger once
It 1st needs to be FALSE then it can become true
It won’t trigger ever again if it always be true
So when it resets it becomes 0,000000
So it is NOT greater than 0,01 and now when it is it can again become true and kick in action

That is why i set there such low value

And what you have WHICH IS WRONG works because you are checking if its LESS than 0,01
That is kinda one of the lowest possible time you can check in gdevelop to fake something happening only ONCE

Set that 0,01 to 0,1
And you will have very un pleasant experience with sound

Fak you picked wrong person
I am here well know of making walls of text
But if you still don’t get somthing i am ready to create more walls

1 Like

Nah I do really appreciate all the help from the walking encyclopedia if it means it’s detailed and I get examples. The CAPS words really do set up the cadence pretty nicely. I appreciate it, m8.

I do have to ask, you focused on why I should put “greater than” rather than “less than” but you never pointed out my removal of the “Trigger once”. I tried adding the “trigger once” condition afterwards and it works, due to luck of the number being 0.01 i gather (didn’t try 0.1 yet). But without it, it appears to work just as well, soooo why the trigger once in the first place?

1 - Once a user told me that i am offending him by USING ALL CAPS on some words
Cause he felt like i am treating him like idiot doing so
And he failed to understand i am trying to point out what is most important here and not just allow you to read all and pay attention to what you want and not to what you should

So NO that is best indication for that you need to pay very close attention to it
So i am glad someone do gets the point of using caps on some words

2 - For something you solved for me i was told is impossible for over 2 years even if it was easy but i simply did not search it or even try to find it
I am more than happy to explain WTF you want here
Just don’t assume i am encyclopedia i do not hold all data

3 - I explained to you why removal of trigger once did work for you
But i think i omitted some steps
Again
Trigger once works like this SOMETHING is not true then it can become true
And if it become true then run action only once
And that created a loop here
Now its again waiting for condition to become false and then switch to true to be able to kick in action again
Example

Condition
W key is pressed
Trigger once

Action
Play Sound Fart.mp3

You need 1st NOT to have that W key pressed for it to kick in this action to play sound
AFTER you press it you can hold it till world ends but that sound will play ONLY ONCE
If you however release it and press it again you will hear sound again
That is how trigger once works

Events in gdevelop runs (if your game runs 60 FPS) 60 frames per sec
So they are read and executed 60 times EACH SECOND
So if you leave play sound action without any condition
You will spam it 60 times PER SECOND
Or how many times engine can handle to play them in rapid succession

NOW
You can have VERY fractional values in gdevelop but detect them in real time is another story
0,01 is almost for us humans ONE single moment so if you spam sound from 0,00 to 0,01
You will hear it only once
Cause that is how much your ear can catch or how fast engine can play it over and over
Like we could have display (TV or monitor) with 300 refresh rate
Or 200
Do you think your eye can catch the difference?
For sure you can 30 vs 60 maybe even 120
But could you tell difference between 200 and 300?
That is something you DO NOT need to answer

So now you check if some timer is below 0,01
How many times you should hear sound playing?
EXACTLY
That is why it did work for you

NOW try to add some other logic to your game
Something that will eat up performance
And your game will not be able to detect is it less than 0,01
Cause it will do other calculation on frame where it was below 0,01
That is why i said it will stop working for you soon
Heck if that crap will not be able to check if its below 0,01 then trigger once will not help
Look
Like i said condition needs to become false for it to be able to become true
You are only checking if timer is grater than 0,01
BUT engine needs to check if its not greater than 0,01 (so if its less than) to allow condition to become false and then true again

So with enough lag or game logic you will create loop in which it will not be possible to properly detect it
So you will need to set it to 0,02 or 0,05 or whatever
There is always some safe spot
You could just set it to 1 or even 1,5 cause that is still less than 2
But then you are narrowing margin for which it can check if it is actually above something and you end up with same issue as with if it would be too low
BUT like i said 0,01 is kinda minimum here well close
0,05 would be more safe minimum

So you DID NOT make it work
It was only working for so short time frame for you it felt like it played only once
Please by my guest and set mod(TimeFromStart(),2) < 1

WITHOUT trigger once
And keep there that play sound action just 1st set your volume to max
And then i can guarantee you you will NEVER again run it without trigger once
Heck use headphones

1 Like

1- Well you can’t please everyone

2- Beginners luck, The encyclopedia also cannot hold all the data, as new things are created/improved/discovered/fleshed out in X field, they require updating. Point being I accept that not everyone knows everything or can help but you’re better than me here so as far as i’m concerned, you’re an encyclopedia. I can see from the help posts there are 3-5 main encyclopedias roaming around in here with varying degrees of exposition complexity.

3- I do confirm that ear cancer did occur. To be fair, unless my read is incorrect, in the previous post you explained why greater than 0.01 is extremely important and how it ties to the trigger once but didn’t explain how the trigger once contributes to the event as a whole. I assume that because everything is interconnected it’s logical but I struggle to comprehend programming logic so it has a harder time squeezing into my brain.

I appreciate it, m8. Your explanations are very detailed but I will certainly need to get back to this and read a few more times to digest it properly.