I’d like to make all dogs to start simultaneously when I press space_bar down. And actually I made it. But I got one question after I found the outcome was different from my expectation, [run_last]. CoSpaces Edu :: run_last.
The location of [ When Key is down ] is different from the one in [ run_all ].
CoSpaces Edu :: run_all
Please give me some explanation and the principle of CoSpaces about the reason why the outcome is supposed to be different.
Many thanks in advance,
PS) To play CoSpaces, please don’t forget to press space_bar down.
I believe you can’t have multiple instances of the same type of event (e.g. press Space bar). In your run_last example it is running either the first or the last instance of the event.
@Nikolay, can you confirm?
Geoff @ TechLeap
when you create a new event handler for the same key pressed, it overrides the previous event handler. That allows user to cancel or edit handlers.
You could put all the run separate block for all the dogs in the list inside one handler and they would move as you expect.
I think it is good to know the design principle of CoBlocks for this case. Under which circumstance and which event handler can be overwritten? What’s that for?
If you let me know, I will just follow the rule.
Sure, I will give you an example:
if you want to do something when the space button is clicked one time, when this button is clicked second time do another action and stop reacting to clicks.
In the following sample when you click space the dog enters the playful mood, when you click second time it moves and stops to react on next clicks:
Feel free to remix the CoSpace and explore it.
Hope that helps
I am sorry that my question was not so clear. You might misunderstood what I like to know.
To make it clear, does all event handler is being overwritten inside the run_function of my run_last Space? If not, what kind of event handlers are overwritten and what are not?
In my case, line4_event is not overwritten and line7_event is overwritten.
PS) Very sorry for annoying your team with series of dumb questions in these days.
The reason your collision event handler is NOT being overwritten, is because you are feeding it a different Item every time.
The keyPress event handler is overwritten every time you loop through.
Here’s what I would do:
Here’s a remixable version of the above code:
Geoff @ TechLeap
The handler is overwritten if all of the parameters match -
i.e.: same CoBlock, same button, same press event.
If at least one of the parameters differs, the handler is different and will not be overwritten.
I will close this issue.
Thank Nikolay and Geoff for your good response. I need to study more.