MrxTutorial
Module: mrxtutorial.lua
Overview
MrxTutorial is the base class for a single tutorial. It handles the activation / completion / cancellation lifecycle and the bookkeeping of the events that drive it. It is deliberately generic: the three Setup*Criteria hooks are where a concrete tutorial subclass defines when it activates, completes, and cancels. Out of the box only SetupCompletionCriteria does anything (a 20-second auto-complete timer). The manager that owns the current tutorial and its net-sync is MrxTutorialManager.
Inheritance
- Inherits from:
none β base/utility module - Imports:
MrxTutorialManager
Instance pattern
Not per-uGuid β same class-factory pattern used elsewhere in resident/: Create(mModule, self) is self = self or {}; setmetatable(self, {__index = mModule}); return self, no tInstance registry. It tracks the following key fields:
_tEvents: A table to store handles of created events.sName: The name of the tutorial.
Functions
Create(mModule, self)
Constructs a new per-instance table for the tutorial using the moduleβs prototype. Initializes an empty table for event handles.
DestroyEvents(self)
Destroys all registered events by deleting them and clearing the _tEvents table.
GetName(self)
Returns the name of the tutorial.
ActivateTutorial(self, bDontNetSync)
Activates the current tutorial using MrxTutorialManager.SetCurrentTutorial. Destroys any existing events and sets up completion or activation criteria based on success.
EndTutorial(self, bComplete)
Ends the current tutorial using MrxTutorialManager.HideCurrentTutorial. Destroys all registered events and either destroys the tutorial if completed or sets up activation criteria otherwise.
SetupActivationCriteria(self)
Empty in the base class β an override point. A subclass fills this in to register the event(s) (via _CreateEvent/_CreatePersistentEvent) whose firing should call ActivateTutorial. Called when a tutorial canβt activate yet (or after it ends without completing), so it re-arms itself for next time.
SetupCompletionCriteria(self)
Sets up the criteria for completing the tutorial by creating a relative timer event that triggers EndTutorial after 20 seconds.
SetupCancellationCriteria(self)
Empty in the base class β an override point. A subclass registers the event(s) that should end the tutorial without completing it (e.g. the player did the wrong thing), typically calling EndTutorial(self, false).
_CreateEvent(self, nEventId, tEventArgs, fCallback, tCallbackArgs)
Creates an event with the specified ID and arguments, registers it as a callback, and stores its handle in _tEvents.
_CreatePersistentEvent(self, nEventId, tEventArgs, fCallback, tCallbackArgs)
Creates a persistent event with the specified ID and arguments, registers it as a callback, and stores its handle in _tEvents.
Events
This base class subscribes to nothing itself. It only provides the plumbing: _CreateEvent wraps Event.Create and _CreatePersistentEvent wraps Event.CreatePersistent, both stashing the handle in self._tEvents so DestroyEvents can tear the whole set down at once. The only event the base class actually creates is the Event.TimerRelative (20 s) in SetupCompletionCriteria. Subclasses use these helpers to register their own criteria events.
Notes for modders
- To build a real tutorial, subclass this and override the
Setup*Criteriahooks usingself:_CreateEvent/self:_CreatePersistentEventβ always create your events through those wrappers soDestroyEventscleans them up (otherwise you leak event handles between activations). - The default
SetupCompletionCriteriaauto-completes after 20 seconds; override it if your tutorial should complete on a real gameplay condition instead of a timeout. ActivateTutorial(self, bDontNetSync)returns whether activation succeeded; on failure it falls back toSetupActivationCriteriato try again later. PassbDontNetSync = trueon the receiving side in co-op so you donβt echo the net event back.