I don't really know it's an issue in your specific case, but maybe it's due to broadcast [mesg] and wait
being a blocking call.
It waits for each scripts being called to finish before settling to the next instruction.
I think in your experiments with unrelated forever
loops, everything was done in parallel.
You could try the broadcast [mesg]
block to launch scripts in a similar way.
Maybe this is wanted behavior, as it guarantees that TickGame
is executed before TickPlayer
and update
.
But please keep in mind that this may slow down the main loop if some heavy calculation could've been done in parallel in some of the called scripts.
Another option would be to use the the send [mesg] to [object]
block, as it allows to be more specific about what object is the target of your message, and to send the same message to different objects at different times, mainly.
I'm pretty sure that this may comes with some performance improvements.
With all that's said, I'm not sure whether it will help you in gaining performance or not so it's best to try & see
Unrelated:
Do you know about the wrap
block?
This is the equivalent of the Run without screen refresh
option in scratch, but in a more versatile way as it permits to be used on very little specific parts of your code without creating a whole new function ("block").
Maybe it could give you a speed gain too.
Also, it may be interesting for you to look after the tell [object] to [code]
as it permits to executes code as another object (you can try tell [player] to [move 10 steps]
to get a feeling of what I mean.
You could execute literally any piece of code, be it several instructions, a specific function or even another tell
block within the tell
block!
And as I'm talking about what things Snap! permits over Scratch, don't forget that functions in Snap! can be defined globally (which means that if you have created a fall
function, you could use it in your rock object, but also in your player object).
All of those thing may be interesting to consider when you're trying to design your program!
Also, I think using Snap! for games is totally relevant, even if it's not the main purpose of the language, as it permits to process audio, graphics and input in some very nice and simple ways.