If you write a lua cs like
function onBegin()
disablePause()
...
end
and then use a lua cs trigger (but with unskippable = false) to trigger it, then you will actually have 2 frames to skip the cutscene, even if the lua cs seems to prevent pausing
yeah i know we should set unskippable = true in this case, but i just want to write everything here, in case you think this should be improved, or someone else curious about what actually happens
order-or-operation analysis:
Frame 1.
LuaCutsceneTrigger.OnEnter called (when Player.Update)
LuaCutsceneEntity is created
LuaCutsceneEntity is to be added to scene
LuaCutsceneEntity.OnEnter invoked
Level.Update done
Frame 2.
EntityList.UpdateList, LuaCutsceneEntity is actually added into the scene
LuaCutsceneEntity is a CutsceneEntity, so Level.StartCutscene is called, and LuaCutsceneEntity.OnBegin is called
Level.StartCutscene makes it possible to skip cutscene this frame
LuaCutsceneEntity.OnBegin adds a new Coroutine(onBeginWrapper(level)) as a component of itself
private IEnumerator onBeginWrapper(Level level)
{
yield return onBeginRoutine;
EndCutscene(level);
}
Level.Update begin
- Check if pause button is pressed
- If not pause,
Scene.Update
LuaCutsceneEntity.Update, which leads to its Coroutine component update
- Coroutine's enumerators consist of one enumerator
onBeginWrapper(level), so onBeginWrapper(level).MoveNext is called, which makes enumerator.Current = onBeginRoutine
onBeginRoutine is pushed onto Coroutine's enumerators stack
Frame 3.
- You can still pause and skip cutscene this frame
LuaCutsceneEntity.Update, so the Coroutine update
onBeginRoutine.MoveNext is called, which finally calls disablePause, that makes level.PauseLock = true, so you can't pause from now on
- But pause check is before this
Frame 4.
- You can't pause this frame
If you write a lua cs like
and then use a lua cs trigger (but with
unskippable = false) to trigger it, then you will actually have 2 frames to skip the cutscene, even if the lua cs seems to prevent pausingyeah i know we should set
unskippable = truein this case, but i just want to write everything here, in case you think this should be improved, or someone else curious about what actually happensorder-or-operation analysis:
Frame 1.
LuaCutsceneTrigger.OnEntercalled (whenPlayer.Update)LuaCutsceneEntityis createdLuaCutsceneEntityis to be added to sceneLuaCutsceneEntity.OnEnterinvokedLevel.UpdatedoneFrame 2.
EntityList.UpdateList,LuaCutsceneEntityis actually added into the sceneLuaCutsceneEntityis aCutsceneEntity, soLevel.StartCutsceneis called, andLuaCutsceneEntity.OnBeginis calledLevel.StartCutscenemakes it possible to skip cutscene this frameLuaCutsceneEntity.OnBeginadds anew Coroutine(onBeginWrapper(level))as a component of itselfLevel.UpdatebeginScene.UpdateLuaCutsceneEntity.Update, which leads to itsCoroutinecomponent updateonBeginWrapper(level), soonBeginWrapper(level).MoveNextis called, which makesenumerator.Current = onBeginRoutineonBeginRoutineis pushed onto Coroutine's enumerators stackFrame 3.
LuaCutsceneEntity.Update, so theCoroutineupdateonBeginRoutine.MoveNextis called, which finally callsdisablePause, that makeslevel.PauseLock = true, so you can't pause from now onFrame 4.