World, ModuleInit

VVMM

Trainz Scripter/Developer
I am using the message World, ModuleInit to determine whether the object is being loaded in Surveyor or Driver.
In TANE this works perfectly.

In TS12 or TS2010 there seems to be a bug (?). ModuleInit is sent only when loading Driver, but not Surveyor (looked in JetLog, no message sent). Is there any way I can determine if Surveyor finished loading? Is this a long forgotten bug that has been fixed only in TANE? Or is it another way?

Thanks!

P.S.: I cannot use World.GetCurrentModule() in Init() because I am using <MapObject>.GetId() and this returns -1 when called in Init().
 
Last edited:
The message ModuleInit() should not be sent in Surveyor mode. It is normally used to call a routine to initialize code that should only be executed in Driver mode.

If TANE now sends the message then that could be regarded as a bug in TANE.
 
Why not? From the example on the wiki here: http://online.ts2009.com/mediaWiki/index.php/ModuleInit_Message I understand that it is normal for the message to be issued on whatever module is loaded. Then we can always check with World.GetCurrentModule() what is the current module loaded.

If you say this is a bug, how can I access an object's ID (with GetId()) when it is loaded in Surveyor? I call the GetId() in Init, but it returns -1 instead of a proper ID, that's why I used the ModuleInit. If called there, the ID returned is valid.

I can only think that the ID is assigned only after the Init() has finished and the ModuleInit message was a convenient way for knowing when loading has finished and IDs are assigned.
 
Last edited:
Well, it depends on which object you are trying to access. Some objects such as train are not loaded in Surveyor. It might be necessary to introduce a Sleep() loop until the returned ID is not -1.

It is possible that the TANE devs needed to change the behaviour to solve an issue with IT, for example.

The ModuleInit() message is a workaround to solve issues caused when going from Surveyor to Driver mode via the F2 button, so if Surveyor is the only module loaded then those issues don't arise.
 
Last edited:
It's been my experience that quite a lot of stuff just isn't loaded when Init() in a user script is called. One warning I got a couple of days ago said that the user interface wasn't complete when I tried to load the handler for Andi's MessageBox debugger. I moved it to a ModuleInitHandler and it worked fine. This was for T:ANE.

For simple scripts it doesn't seem to matter but as they get more complex, I invariably have to resort to using a ModuleInitHandler. How this relates to the original Ctrl F2 issue, I cannot say, but nearly all my scripts use it.

Interface.Print doesn't seem to work in Surveyor (Session) either which a bit irritating.
 
Managed to do as trev999 said: created a thread that is called by init and makes a while(GetId() == -1) Sleep (1.0); It continues when Id != -1 so this fixes my problem and makes my script compatible with TS2009+ without any other modifications.
 
Back
Top