PDA

View Full Version : TRS19, SendMessage & Sniff...



Travlar
September 19th, 2018, 03:42 PM
Greetings,

I have some scripts that worked perfect in TANE SP2. Due to the job & life in general, I completely missed TANE SP3 and now find myself attempting to get my scripts working in TRS19.

I have several things that are supposed to happen in the Init(void) method to ready the locomotive when it is loaded. The problem is, the physical changes that are supposed to be made are not. Which makes me wonder why they are not being processed.

In this method I also setup message handlers so various things can be listened for via Sniff. I also set Sniff to start monitoring.

When I start the game and load my session, I immediately can see that my method that is supposed to determine the direction of the locomotive and set lights accordingly has not run. If I use one of my scripted driver commands, I get absolutely nothing. I have not figured out how to get a message window to show, so I have not been able to debug using the help of a message window.

So 2 things. Is there a message window I can write debug messages (or any message) to in TRS19 and if so, how? Secondly, has something changed in the way that SendMessage, MessageHandler, and Sniff work in TRS19? I have double/triple checked the wiki and I have them set correctly per the wiki.

I have been at this almost non-stop for 3 days now and it has me frustrated beyond all hope.

Edit: Grammar

shaneturner12
September 19th, 2018, 04:17 PM
What are your settings like on the first tab in Trainz Settings?

Shane

EDIT: Scratch that - it's actually the Dev tab I'm interested in - particularly the 'compatibility mode' setting.

Tony_Hilliam
September 19th, 2018, 04:24 PM
Have you checked
http://online.ts2009.com/mediaWiki/index.php/Asynchronous_Route_Streaming
I would also search on asynchronous streaming +Trainz for the latest discussions

Travlar
September 19th, 2018, 04:39 PM
What are your settings like on the first tab in Trainz Settings?

Shane

EDIT: Scratch that - it's actually the Dev tab I'm interested in - particularly the 'compatibility mode' setting.

Maximize Compatibility is what I have set.

Travlar
September 19th, 2018, 04:53 PM
Have you checked
http://online.ts2009.com/mediaWiki/index.php/Asynchronous_Route_Streaming
I would also search on asynchronous streaming +Trainz for the latest discussions

I did look at that and have wondered if it is related to GameObjectID() as I might need to change the GetID() to use GameObjectID().

Travlar
September 19th, 2018, 05:43 PM
Shane,

Can you provide an example of how to implement GameObjectID?

If I understand this right, where I used to do something like this;

int myID;

myID = me.GetID();

would need to change to use GameObjectID, but I have not been able to find an example of how to get this ID for my locomotive.

I apologize asking here, but I could not find an example searching TrainzDev and I do not have access to post there.

WindWalkr
September 19th, 2018, 09:05 PM
Maximize Compatibility is what I have set.

The suggestions re/ GameObjectID and etc. are good ones for moving forward, but won't directly resolve your problem here. With "Maximise Compatibility" enabled, the script environment will generally be very similar to T:ANE SP2 and you shouldn't need to make any real changes. Since you don't seem to have any ideas on what's failing, I'd suggest starting by trying to trace the code and determine the point at which reality diverges from your mental model of what's going on.

Specifically:
* Configure a minimal test session.
* Enable developer mode in the settings.
* Enable script logging in the settings.
* Enable script message logging in the settings.
* Enable display of script exceptions in the settings.
* Restart the game if necessary.
* Add Interface.Log() statements throughout your code so that you can determine what is being called, and in what order. Log the start of functions and any relevant control flow (if statements, return statements, etc.)
* Clear your logs.
* Launch directly into your session from CM to avoid unnecessary additional log entries.
* Proceed until the problem occurs (hopefully this is immediate).
* Pause the game.
* Open the logs window.
* Review the output, to see which of your logs have fired off and which messages have been dispatched.

hth,

chris

Travlar
September 19th, 2018, 11:12 PM
The suggestions re/ GameObjectID and etc. are good ones for moving forward, but won't directly resolve your problem here. With "Maximise Compatibility" enabled, the script environment will generally be very similar to T:ANE SP2 and you shouldn't need to make any real changes. Since you don't seem to have any ideas on what's failing, I'd suggest starting by trying to trace the code and determine the point at which reality diverges from your mental model of what's going on.

Specifically:
* Configure a minimal test session.
* Enable developer mode in the settings.
* Enable script logging in the settings.
* Enable script message logging in the settings.
* Enable display of script exceptions in the settings.
* Restart the game if necessary.
* Add Interface.Log() statements throughout your code so that you can determine what is being called, and in what order. Log the start of functions and any relevant control flow (if statements, return statements, etc.)
* Clear your logs.
* Launch directly into your session from CM to avoid unnecessary additional log entries.
* Proceed until the problem occurs (hopefully this is immediate).
* Pause the game.
* Open the logs window.
* Review the output, to see which of your logs have fired off and which messages have been dispatched.

hth,

chris

Excellent information!!! I knew there had to be a way. I'll get this set up and give it a try.

Thank you very much Chris. I appreciate the feedback.

pcas1986
September 20th, 2018, 12:49 AM
I suggest "minimal" is the key word here. Just add the least amount of assets that your script is looking for. You might comment out most of your code and add it back in as you identify those bits that do work. I tend to add log statements like "in init" or something meaningful to you.

Andi's MessageBox debugger was still working last time I tried it but that was probably TANE SP2.

Make sure to clear the log regularly as it gets noisy with all the debug stuff on.

Travlar
September 20th, 2018, 07:33 AM
The suggestions re/ GameObjectID and etc. are good ones for moving forward, but won't directly resolve your problem here. With "Maximise Compatibility" enabled, the script environment will generally be very similar to T:ANE SP2 and you shouldn't need to make any real changes. Since you don't seem to have any ideas on what's failing, I'd suggest starting by trying to trace the code and determine the point at which reality diverges from your mental model of what's going on.

Specifically:
* Configure a minimal test session.
* Enable developer mode in the settings.
* Enable script logging in the settings.
* Enable script message logging in the settings.
* Enable display of script exceptions in the settings.
* Restart the game if necessary.
* Add Interface.Log() statements throughout your code so that you can determine what is being called, and in what order. Log the start of functions and any relevant control flow (if statements, return statements, etc.)
* Clear your logs.
* Launch directly into your session from CM to avoid unnecessary additional log entries.
* Proceed until the problem occurs (hopefully this is immediate).
* Pause the game.
* Open the logs window.
* Review the output, to see which of your logs have fired off and which messages have been dispatched.

hth,

chris

Okay. Did all these things and I can at least see that my custom driver command is sending a message. But I don't see any of my Interface.Log() comments anywhere. I'm using the latest beta version if that makes a difference. I can see where the Init() fires for the locomotive I'm using, but it seems like nothing is processed after that. I can only see one "error" and it says that there is an incompatibility with <kuid:401543:1115> which is for 4.2 I believe.

Without being able to debug, I think I'm just trying to cut down a tree with a toothbrush. Needless to say, I'm frazzled at this point after 16 hours of this today.

Thanks to all of you, I appreciate it.

WindWalkr
September 20th, 2018, 08:05 AM
But I don't see any of my Interface.Log() comments anywhere. I can see where the Init() fires for the locomotive I'm using, but it seems like nothing is processed after that.

Okay, so to be clear about this:
* You are seeing an Interface.Log() from your Init() function.
* But you're not seeing any later logs?

What are you expecting to trigger the later logs? Are you listening for some specific message? If so, are you seeing that message in the logs?

chris

Travlar
September 20th, 2018, 06:15 PM
Okay, so to be clear about this:
* You are seeing an Interface.Log() from your Init() function.
* But you're not seeing any later logs?

What are you expecting to trigger the later logs? Are you listening for some specific message? If so, are you seeing that message in the logs?

chris

In my Init() function, I call to other methods to set the locomotive up at the start. One of these methods gets the direction of the train and sets lights and a FRED. Just prior to calling the Directions method, I have Interface.Log("Entering Directions"); and then the method is called. I am not seeing this "Entering Directions." Furthermore, at the beginning of the Directions method, I have Interface.Log("Directions Enter"); and this is not showing up either. Other methods setup sounds and effects and I have similar Log statements that are not showing up.

I'm just going to scrap the whole thing and start from scratch. I hate to have to write over 4k lines of code again, but something is missing and it obviously is not going to be found this way. I've programmed for over 30 years and I have never had an issue go for this long. I will have to look and make sure I am not trying to call something from a piece of payware that might be blocking or maybe from an obsolete library? I don't know.

I apologize for taking your time, but I do thank you for the information. This will definitely help as I start from scratch and I'll build in my Log statements from the beginning this time. I'll go and see if I can figure out GameObjectID before I start this time also.

Sincerely,

-=Travlar=-

pcas1986
September 20th, 2018, 06:57 PM
Sounds to me that the asset isn't fully loaded. I usually defer setting up my own stuff by placing such calls in a separate thread. Sorry, I don't have an example handy as I am away from home.

Travlar
September 20th, 2018, 09:48 PM
Okay, so to be clear about this:
* You are seeing an Interface.Log() from your Init() function.
* But you're not seeing any later logs?

What are you expecting to trigger the later logs? Are you listening for some specific message? If so, are you seeing that message in the logs?

chris

Just for information. For giggles I installed TANE SP2 and my scripts are not working there either. I tried with 3 different locos, all which have slightly different scripts and nothing. So I'll go from scratch as obviously I did something that TANE and TRS19 does not like.

If I figure it out as I build from the ground up, I'll let you know.

Travlar
September 20th, 2018, 09:51 PM
Sounds to me that the asset isn't fully loaded. I usually defer setting up my own stuff by placing such calls in a separate thread. Sorry, I don't have an example handy as I am away from home.

That is exactly how it seems. My attachments on the loco which are supposed to be invisible once the direction is discovered are all out in the open, so I know that section at least has not run or the mesh would have faded out.

I did this for testing. If I get these to work again, they will be invisible until direction is determined and then the mesh will become visible. None of the animations are working either. Thank you all for your help.

Travlar
September 22nd, 2018, 06:41 AM
So here is one for you. I did not change anything in my script, but from the launch screen, settings, dev panel, I changed to Maximize Performance.

I started the game, went to my test route, viewed sessions, picked the one I had been working on, edited the session and when it came up, I saw my loco's lights flash and turn off. That to me meant that the script ran. So I sent my custom command and it fired off like it should.

I then coupled to a 2nd loco of the same type and everything in the script fired like it was supposed to. I played around for about 30 minutes and loaded my reefers and bam! The reefer scripts fired off like they are supposed to and the little reefer engine started cooling off the reefer.

When the temp came down, the reefer shut off as it is supposed to. After about 10 minutes, the reefer heated up enough to kick the reefer back on and start cooling again. Awesome.

I jump out, make a few changes with locos and fire the session back up. OMG! Back to square one. Nothing fired off on anything. But, if I change to Maximize Compatibility, start the game, exit, switch to Maximize Performance, start the game, fire up the session, all the scripts work again. So at this point, since I can get the scripts to run, I wonder if this is a bug?

Edit: Grammar

WindWalkr
September 23rd, 2018, 11:10 PM
In my Init() function, I call to other methods to set the locomotive up at the start. One of these methods gets the direction of the train and sets lights and a FRED. Just prior to calling the Directions method, I have Interface.Log("Entering Directions"); and then the method is called. I am not seeing this "Entering Directions." Furthermore, at the beginning of the Directions method, I have Interface.Log("Directions Enter"); and this is not showing up either. Other methods setup sounds and effects and I have similar Log statements that are not showing up.

The loco's Init() method should definitely be called during the startup process. I'd suggest adding a log at the very beginning of that method, before doing anything else. If that doesn't fire off, then you have something fundamentally wrong - perhaps even something as "obvious" as editing the wrong asset's script, or forgetting to submit your changes prior to testing, or a missing dependency. (I'm assuming here that you are referring to the loco's Init() method and not some other kind of asset - if it's a library or interior or etc, then you should focus your effort on working out why that asset isn't being loaded.)

If, however, the Init() method is being called but isn't making it all the way to the end, then you have two possibilities to consider:

1. That a script exception is being thrown. This should show up in-game if you have it enabled.
2. That a control-flow statement (such as "return") is being used to exit prematurely.

If you can't find evidence of either, then start moving the log statement down through the function until it stops working. This will allow you to narrow things down to a specific line (and if that's a function call, you can then add logging to the function and repeat the process..)


In light of your other post, I'd also suggest ensuring that you are not trying to edit the script while you have the session open in another window. The game won't be able to reload the asset while you have it open, so your changes won't take effect and you won't be testing the version that you think you are.

chris