Question about implementation of showLongText

I have a question about part of the implementation of showLongText:

I think I mostly understand the relationship between the game.onUpdate handler and the pauseUntil callback… but I can’t find where the onUpdate handler is actually removed. I’ve confirmed that code doesn’t continue to run after the dialog is closed, but I can’t seem to find whether it’s the scene pop or the completion of the pauseUntil or… ? that ends up ultimately removing the onUpdate that’s drawing the dialog.

Thanks!

It’s the scene.pop; the on game update events are registered on the scene’s event context, and will cease to run when you push or pop a scene and another event context ‘takes over’.

For what it’s worth, it does look like the pause until there is unneeded; the update event is guaranteed to run synchronously with the rest of the game update loop, so we can probably just swap controller._setUserEventsEnabled(true); to where done = true; is set and drop the done boolean and the async pause. Haven’t tested that though

1 Like

Awesome. Thanks so much.

I was also curious about controller._setUserEventsEnabled(false) / controller._setUserEventsEnabled(true) calls. From its name, that doesn’t look like a “public” api. My intuition was that it suspended processing of user input for things like the sprite controller block. But it seems like pushing a scene is enough to prevent input getting through to a sprite below. Do you mind explaining a little more about the _setUserEventEnabled?

1 Like

Actually, I think you are right on that, it’s likely fully redundant. I think it might have been added at a time where we had some bugs around controller events not being properly attached to the scene, but it doesn’t seem necessary anymore. (and yes, you’re right on what that function does, it flips on a flag which determines which events are triggered: https://github.com/microsoft/pxt-common-packages/blob/master/libs/game/controller.ts#L87)

_ at the front of a method / function name is generally our ‘not private, but don’t make it trivially exposed’ indicator; we probably have a little bit less of a bar on changing them as they’re thought of closer to implementation details, but the main reason we mark them that way is so they don’t show up in autocomplete (as we filter them out).

1 Like