My students want to do this: When they collect all 5 diamonds in one scene, they automatically go to the next scene. How do we code this?
The easiest way is to create a variable with the taken diamonds count and for every diamond create onClick event. In that event you have to delete the current diamond from scene, increase the taken diamonds count (or decrease the number of diamonds to take) and check if all the diamonds are collected.
That handler for the diamond can be put into the function:
I have created a demo scene, you can remix it to see details
Can you please explain to me the first block? It is the read ‘addDiamond’ block. WHere is this block?
addDiamond is a function. It is declared above the “When play clicked” section.
In the “When Play clicked” section this function is called for every diamond. And the body of the function is executed 5 times.
Here’s a tutorial that should help you better understand functions in CoBlocks!
I hope this will help you!