Stop a timer when collected items

Hi there,

I want to create a timer that stops when I reach checkpoint or collected a certain amount of items.

Can anybody help me how to do this with CoBlocks?

Thnx!

Hi @Bjorn_Hartog,

Can you post a pic of your code so far? Here’s some clues as to how to go about coding this:

A timer will generally use a loop, so to stop it you need to interrupt that loop, and to do that you need to be constantly checking whether you’ve reached the checkpoint or collected a certain amount of items, using a conditional check.

We can use variables to store the state of something, e.g. checkpoint_reached = true/false, then we can use that in our conditional check.

Hope that helps! Let me know if you have any further questions about this.

Regards,
Geoff @ TechLeap

2 Likes

Hi @techleapnz ,

Here’s my code so far. In this code I want to stop the timer when the camera collides with the diamond but i’m stuck.

Regards,
Bjorn Hartog


Have a look at this simple start/stop timer I created to demonstrate what I explained in the previous post:

Hope this helps! Let me know if you have any further questions about this. If this solves your issue, please mark this post as the Solution.

Many thanks,
Geoff

1 Like

@techleapnz,

Thank you for your solution.
Next thing I like to try is to first collect the 5 diamonds in order to stop the time.

Here is my CoSpace so far.

Regards,
Bjorn Hartog

1 Like

It’s looking good. I encourage you to bring your HUD (Heads-Up Display - timer + score) closer to the Camera and reduce the size at the same time, as it is getting cut off when looking down.

Thnx! HUD is now closer to the camera.