[Solved] Different Times In The Same Object

I have a Ghost that chases the player and when the timer reaches (Ghost’s Random Time Variable) it stops and teleports to another location.

At the beginning of the scene, Ghost’s Random Time Variable will set to Random in Range 4 to 6 which determines when the Ghost’s will teleport. It works fine with only one object present but when there’s multiple Ghost’s object in the field only one teleports. The problem is this, If I put two or more Ghost object, For ex. Ghost 1 will teleport in 4 sec. and Ghost to is 5 sec. The Ghost 1 will teleport first and the timer will reset and the other Ghost will not able to teleport because the timer was already resets. I try to put for each object on the part where it resets but it doesn’t work. I just want a the Ghosts to have different time to teleport and chase.

Hi FutureGameDeveloper, as you’re using multiple of the same object you’re going to need to look into the FOR EACH OBJECT events.

This will allow each object (you choose) run the logic independently of each other.


1 Like

I try to put it above all the events of ghost but it didn’t work as well as putting for each object below the EnemyGhostVariable + 3 but it doesn’t work too.

Well as you have set up a timer for each instance so you need to ForEach instance of ghost then do.


Here the project https://drive.google.com/file/d/14IzTvTz8z6qiNwni2CNAThRB2_-SwAkd/view?usp=sharing


Can you help with it? I try it but it doesn’t work. I think I’m missing something here.
Here’s the project: PR - Google Drive
I put comments on the events that needs to fix. Those events works perfectly on the object when I put only one but when I put two or more, problem comes.

Please help me fix the Ghost object as well as the Ram.

Ghost: Chases the Player and when the Timer is greater than the Random Variable, It Teleports to another random location then repeat.
Ram: Moves slowly and in random direction and when the Timer is greater than the Random Variable, It dashes to the current location of the Player then it needs to stop when collided to a wall then repeat.

You can put first 1 Ghost and Ram to see what results I’ve been looking for. The goal is just to make it work also in 2 or more of each object. Thanks in advance!

I’m not at my laptop right now when I get home I’ll check

Edit: Here I made some mods but I don’t know if is this what you want all mods are in orange
Only the ghost I guess is the same for the rest, if not just update the thread.

1 Like

I’ve tested it and unfortunately it’s the same than before. I’ve found out that the major problem is the time reset.
For example, there where 2 Ghosts then they’ve got different variable for the timer.
Ghost #1 got “3” which means he will do the teleport action if the timer is greater than “3”
Ghost #2 got “5” which means he will do the teleport action if the timer is greater than “5”
The problem is that when Ghost #1 finished the teleport, it will soon resets the timer and that’s why Ghost #2 will never do the teleport thing because the timer was already resets.
It seems like even if you put “for each object of Ghost”, the timer of all Ghosts will reset if one Ghost manage to reach the condition first. This is also the problem to the Ram and my other enemies. Is there a way to make every Ghosts have individual timers that will reset for only a specific Ghost and not all of them.

Hey, maybe I fixed it. Is this what you were looking for?
If yes then, here is the file.

Note: Sometimes, these two ghosts disappear at the same time and that’s because you haven’t given much space for getting random number. There is only maximum 2 second disappearing time difference so sometimes, the Random numbers can be same.

1 Like

LOL, I totally forgot to identify each ghost with a different timer, I’m going to update the project and reupload.
Here every ghost will have an UID to identify and added to the timer name os the timers are different for each ghost like “Transport0”, “Transport1”, and so on

1 Like

Thank you so much! @UlisesFreitas and @Muzan! That’s what I didn’t know! I’m sorry for having a lot of problems I only knew the basics of GDevelop. Thanks for helping out!:smiling_face_with_three_hearts:

Was it fixed from your perspective?

1 Like

As Mixen ask is this solved?

1 Like

So I’ve tested out @UlisesFreitas file and it’s not working again and I don’t why. I’ve tried @Muzan file and it works I guess but I don’t know what you’ve did because the only thing I see there is this:

and the others are in the cancel thing (I don’t know what to call it) Can you explain me how does it work?
My goal is to have every Ghost have 4 to 6 in timer randomly and do the events if they reach it individually. For ex:
Ghost #1 (4) 1 2 3 reset then got 5 → 1 2 3 4 reset then got 5 → 1 2 3 4 reset and so on…
Ghost #2 (5) 1 2 3 4 reset then got 6 → 1 2 3 4 5 reset then got 4 → 1 2 3 reset and so on…
Ghost #3 (6) 1 2 3 4 5 reset then 4 → 1 2 3 reset then got 6 → 1 2 3 4 5 reset and so on…
“then got” means they get a new random timer. I tested out @UlisesFreitas file but when the I counted before they do the events, only one Ghost do it and I wait until 6 seconds because that’s the limit of each Ghosts before they do the events, the other Ghosts didn’t do it. But in @Muzan file it looks like what I want but I didn’t know if it’s 4 to 6 timer just like I presented.

Yes, it is 4 to 6 timer and what I did was pack all your events onto a behaviour:

and did some tweaks in your event. You can see it :slightly_smiling_face:.

1 Like

oh, that’s why I didn’t see it. Thank you all for helping me with this!:smiling_face_with_three_hearts:

You can delete those cancelled things.
They are called disabled. We do this using this:

1 Like

Thanks for another tip as well as giving me a new knowledge about making Behavior Functions!
But because of that, I have a new problem.

Can I call objects specifically in creating events with this function behavior? I want to call out the Player’s X and Y position because that’s what I want to be the target because this enemy is a Ram. If not, how can I input it? Like when I want events with collision to another object? How can I specify what object I want?

Sorry, I didn’t get it

Edit: I think I got it now. So, you want Player.X() and Player.Y(). You can’t do that. You can only call objects with the doStepPreEvent and doStepPostEvent and a Custom function.

By using Custom function.

This allows you to create your own action and conditions for your Behavior and add Parameters which is used for input

Maybe you can create a Custom Action function, call Player.X() and Player.Y() from there and do that action at the beginning of the scene or while creating your Enemy, in your Scene Events.

1 Like

I still can’t get it.

1 Like

Its like this for ages
Is it glitching?

1 Like