Help with "on created" block

Hi There
I am struggling to use the “On Create” function correctly. I am hoping someone could please explain how I can use the “On Create” function to run every time I create a sprite of a certain kind (in this case a new type called “Trampoline”).

My son is following a tutorial whereby he is creating three trampolines that bounce back and forth. The idea is to create a “On Created” function every time a trampoline is made.

Here is the tutorial code:

I would expect that we would use the “On Create sprite of kind Trampoline” - however in the tutorial they have managed to use a “On create trampoline of kind Trampoline”?? I can’t seem to create that block - nor did it make sense to me.

Here is my son’s code:

Any help you can provide in explaining how to use the On Create block would be great. Thanks

Welcome, @insaniac !

They just changed the name of the variable. It doesn’t actually matter what the variable is called, whether trampoline or sprite, in the event handler. Just use the same name that appears in the function.

If you really want to change the name, then you should be able to do so. In a block within your function where you use sprite, use the dropdown and select Rename variable… to change the name from sprite to trampoline. Just be careful … it will change everywhere that name is used in your project.

1 Like

Use the “On Created sprite of kind [Trampoline]” block to run code whenever a Trampoline sprite is created. The “On create trampoline of kind [Trampoline]” block might be incorrect. Check MakeCode Arcade docs for more details.