Hi, I’m using a for each object to do a collision test but I’d like to know how to add a delay to the for each object, I tried to place some like in the image below but it doesn’t work.
the project file can be found on this other related topic if required.
I think your issue is that you are resetting a scene variable - if you reset it once, it’ll effectively be reset for ll objects. Instead, use an object timer. It works the same way as a scene timer, but each instance of the timer is specific to the object it belongs to.
So in this event:
replace the scene timer with the object timer.
Remember you’ll also have to start the object timer for each object somewhere else.
I’m not sure what you’re trying to delay. This is the check routine. If you’re trying to delay the checking then the delay should be outside the checker. Either on the first event or the event that changes the variable that triggers the check.
You also can’t use a timer to cause a delay within a loop like a while event. Time doesn’t get updated within a frame. It happens in between. I’m assuming it’s not adding IDs to the array because time isn’t being updated.
You could restart a scene timer everytime a block is dropped. That would keep delaying the update. If that’s your intention.
Object was dropped start timer.
Timer > number then set the variable that triggers the check to true.
That way the timer wouldn’t delay all updates only ones that are triggered through the timer.
You might also need to delete the timer when something is being dragged. So, the timer doesn’t trigger the update while it’s being dragged.
In fact, I have a variable named: (TimeInSec) which defines a countdown before to turn variable OnOff to true. In theory, if an object contains the variable (TimeIsSec) with a value of 2, it’s supposed to wait 2 seconds for the OnOff variable to become true.
I still don’t understand the delay. If an object isn’t checked, it will break the entire circuit from that point on. It seems better to either check the whole circuit or nothing.
You still need to use an object timer.
Here’s why. say 3 objects have a countdown less that the timer value, so all 3 need the OnOff set to true. In the loop, GDevelop comes across the first object, and resets the scene timer.
Then, when the second object is checked, the scene timer is now 0, meaning the object is no longer eligible to have OnOff set to true.
That’s why you need an object timer. Because the reset affects all the other objects relying on it.
What is the purpose of the timer. What problem are you trying to solve?
The timer will not work inside the loop.
DoCheck gets set to true
If DoCheck is true
Reset The object timers
Clear the array and seed it with the IDs of the battery.
Get the last ID from the array and remove it
Place the checker at the location of the ID
If timer is > object variable then add all of the colliding object IDs
The timer is still at 0 so no IDs get added
The while event loops until all of the batteries are tested. It’s still the same frame, so no time has elapsed as far as the condition knows. So, no other objects get added.
The array is empty so the while event stops looping.
DoCheck was set to false, so the check won’t be done again until DoCheck is set to true.
If you’re trying to delay the update then delay the changing of the DoCheck boolean using a scene timer.
The problem is that the Trigger Once won’t be functioning the way you expect.
The very first event, if DoCheck is true it gets set to false immediately. This means the event is run once, then not for a while.
The first subevent resets the timer. This will happen every time DoCheck changes back to true. So the object timers are always reset, and thus never reach the value held in WireBatteryGroup.TimeInSec
.
Like @Keith_1357, I too don’t understand what you are trying to achieve here. If you can describe it in detail, then maybe one of us can better help you.
In fact, I have a variable called TimeInSec which defines the time before this object is activated. I want that if object A has a TimeInSec value of 2 for example, if it comes into contact with a battery, it will take 2 seconds for the OnOff variable to change to true. In short, I’m trying to create a system that delays the transition from OnOff to true according to the TimeInSec value of the object.
I think I understand. You want some wires to have a delay. It might work if get move the timer start action. It’s on a trigger once bust since. It’s a sub-event of the boolean check it inherents that condition. So, it’s going to trigger evertime the routine is triggered.
You could try moving the timer start somewhere else although that would mean the check routine would have to be triggered more frequently. Maybe have a timer elapsed condition outside of the check routine that would trigger the check after a certain time.
The check routine might need to be modified to make partial checks.
I think it will be more meaningful with an example in picture
I still don’t understand the purpose of the delay. Is it a performance issue?
In the object was dropped event instead of setting the boolean to true. You could start a scene timer. When the elapsed time expired you could delete the timer and set the boolean to true which would cause an update.
You could also add something to either delete the timer when an object gets dragged.
Honestly, I can’t make suggestions for something I don’t understand. I personally like the automatic update. It’s your project though . If that doesn’t fit your vision that’s fine. We’ll try to help you with your concept.
When do you want the updates to happen? Automatically, delayed or through a button?
In my test project, it updated.
At the start.
When an object was added
When an object was moved or deleted
When a switch was toggled.
I know my version probably doesn’t match your concept. But the fundamentals are there. It’s just a matter of making some tweaks.