ModuleInit Message

From TrainzOnline
Jump to: navigation, search

Switching directly from Surveyor to Driver mode via the ^F2 shortcut or the Quick Drive button allows a Driver session to be launched directly from from Surveyor.

However Trainz carries out initialisation tasks for scripted objects when they are loaded into Surveyor and many of these do not need to be repeated when the user switches to Driver mode. Some tasks, such as monitoring threads, will be started by the game if Driver is the first module called, but not otherwise. In consequence these tasks will not run if Driver is launched via ^F2.

The message World,ModuleInit is provided to allow this issue to be overcome.

If this handler is added in Init()

public void Init(void) {
   inherited();
   AddHandler(me, "World", "ModuleInit", "ModuleInitHandler");
}

It will be possible to track the change between Driver and Surveyor and take any necessary corrective measures in the ModuleInitHandler method.

void ModuleInitHandler(Message msg) {
   if (World.GetCurrentModule() == World.DRIVER_MODULE) {
      InitialiseDriverTasks();
   }
}

World.GetCurrentModule() allows the current module to be queried from script.

See Also

Personal tools