Uncategorised Scavenger Hunt Of Different Items With Timer

Hello All,

I am having trouble making my scavenger hunt with a timer. I have created a simple code which I thought would work, but didn’t (I am a rookie at this). The Basics of this gam is where you have 60 seconds to find 20 items randomly placed everywhere. Attached is a photo/video of my Code, and please reply to any mistakes I have made, or any suggestions. Thanks you.
Kind Regards, Sebastian Bailey

My Attached Video

1 Like

Please share a remixable version of your CoSpaces if you can - it would be much easier to debug.

2 Likes

@techleapnz, Here it is

1 Like

Here’s what I’d do to fix the timer:

Obviously, this doesn’t account for the condition where all items are clicked before the timer runs out, but then again, neither did your original code.

Also see this CoSpace for a countdown timer HUD:

I also recommend putting all your objects into a list, then iterating through that list to set up your click events.

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

Many thanks,
Geoff @ TechLeap

3 Likes

@techleapnz, Thank You! :hugs:

2 Likes

@techleapnz, i was wondering if you could put a solution to the items, for it isn’t working even when I press all 20 of them. Thanks! :hugs:

Let’s think about what would be needed to “make it work”:

  1. We need to know which items are clickable (put them in a list)
  2. We need to know whether one of these items has been clicked (set an event listener for item clicks and remove it from the list once clicked)
  3. We need to know whether all the items have been clicked (check how many items are left in the list)
  4. We need a way to stop the timer if the list is empty of items (break the timer loop if that condition is true)

Does that make sense?

1 Like

Kind Of ~ Could You Maybe Send Through A Code For 1 Item That I Can Replicate For Each Different Item?

1 Like

Where’s the fun in that?! How about we work through it together instead?

1. Put items in a list - do you know how to do this?

Lists are under the Data category. Have a go at that, and let me know when you’re done.

1 Like

@techleapnz, I have successfully created a list of all the items. What to next?

1 Like

“set an event listener for item clicks and remove it from the list once clicked” == “set an event listener for item clicks” + “remove item from list once clicked”.

1. Set an event listener for item clicks
To set an event listener for each item in the list, we need to use a for each element in list CoBlock (under Control), add a when item is clicked block inside that loop, then drop the oblong element variable (in the Data category) into the oblong “item” space in when item is clicked:

2. remove item from list once clicked
Inside the yellow click event listener block, we need to add a delete item 0 from Items block (in the Data > List category). We then need to replace the 0 (zero) with the “index of item in Items” block (in the same place).

An index is the number place of the item in the list (1st, 2nd, 3rd etc), but the count starts at 0, so zero/0 is the 1st item, 1 is the 2nd item etc.

Finally, we are going to swap the oblong “item” in the index of item in Items block, with the oblong (value of variable) “element” block, so that the 3 blocks kind of look like this:

Let me know if you have questions, or when you’re done.

1 Like

@techleapnz, I have finished, but I am confused about the 3 Blocks thing. Here’s a photo of my code. Could you please help me?

1 Like

Your code is perfect. The 3 blocks basically says, “delete this item from the list of Items”.

Normally the delete block deletes an item at a particular index/position in the list, so in this code we’re feeding in the position of the item we’re currently using in the loop.

Next we need a way to check how many items are left in the list and check this somewhere in the timer code. We just need an if-then block (under Control), a logic = block (under Operators) and a length of Items block (in Data category) to see if the number of items in the list = 0 (zero).

If the length of the Items list is zero, then all items have been clicked.

Have a go at coding that and let me know when you’re done. Don’t worry too much about where you put the code - we’ll look at that next.

1 Like

Hello @techleapnz,

I have completed the code, and the photo is underneath. What to next?

1 Like

Well done! I can see what you want to happen when you win - what should happen when you lose?

We now need to decide where and when this check should occur. It should be checked regularly. I see at least 3 options:

  1. We could have it running in a forever loop,
  2. We could just check it when an item is clicked
  3. We could check inside the timer.

Which one do you think would be best? What are the pros/cons of each?

1 Like

@techleapnz, I have already finished the timer, in which when it reaches 0, you go to a different scene. The code isn’t working, for as soon as I spawn in, it has the WooHoo sign thing. How do I fix this?

1 Like

@techleapnz, can you please help?

1 Like

Hi @Sebastian_Bailey, yes, I can help, but because I have a very busy life, I sometimes don’t get to messages for a day or two.

Thanks for your patience!

2 Likes

That’s ok - thank you for helping me ! :pray:

1 Like

Hi @Sebastian_Bailey, could you please Update the share on your CoSpace, so I can see the changes you’ve made?

1 Like