Expand potential of TCS scripting
#41
Posted 30 April 2020 - 02:09 AM
#42
Posted 30 April 2020 - 03:48 AM
sorry, but I don't understand your question well. The syntax of what? For the script a stroke of the above key combinations will be the same as the mouse click on the ORTS_TCS1 or ORTS_TCS2 cab control.
#43
Posted 30 April 2020 - 04:14 AM
#44
Posted 30 April 2020 - 05:20 AM
#45
Posted 30 April 2020 - 07:41 AM
Csantucci, on 28 April 2020 - 12:52 PM, said:
This is now implemented in OR NewYear MG rev.60 and in the latest official Unstable release, where also all other TCS extensions are now available.
#46
Posted 30 April 2020 - 11:27 PM
Please, give me an advice.
#47
Posted 01 May 2020 - 10:14 AM
you can download here http://www.interazio...ev8.0_provv.zip a new temporary release of the script for the Italian TCS, where I have implemented the check for key combinations Ctrl,(comma) to switch on the on board TCS and Ctrl.(period) to switch it off.
I also suggest you to update tomorrow morning the Testing version of OR. There should be an update in the OR manual, where YoRyan has written the basics of OR scripting.
The SCMT source is quite complicated. Here some hint about the points where the checks are performed. When one of the two key combinations are pressed and when they are released, method
public override void HandleEvent(TCSEvent evt, string message)
at line 1883 of the script is called, and in particular lines from 1908 and further on are activated.
Key combination Ctrl,(comma) or Ctrl.(period) start HandleEvent; evt can have the two values TCSEvent.GenericTCSButtonPressed (when you start pressing the keys) and GenericTCSButtonReleased when you release them; message can be in our case "0" (string) for Ctrl,(comma) and "1" for Ctrl.(period). Within HandleEvent they are converted to integers and then to CommandEvent enums respectively as TCSCommandEvent.Accendi (switch on) and TCSCommandEvent.Spegni (switch off) and become indices for TCSButtonPressed[(int)commandEvent] and TCSButtonReleased[(int)commandEvent].
The relevant elements of TCSButtonPressed are then read within the update loop in UpdateSSBState() (line 1024). That method should be clear.
#48
Posted 01 May 2020 - 12:38 PM
Any chance of incorporating such a function into your changes?
#50
Posted 01 May 2020 - 11:52 PM
YoRyan, on 01 May 2020 - 12:38 PM, said:
Any chance of incorporating such a function into your changes?
Hi Ryan,
I'm happy you're working on that.
With this hook that I added some days ago
Script.Locomotive = () => Locomotive;
you have access to the whole Simulator environment (locomotives, trains, signals and so on), e.g. in the script you can refer to
Locomotive().LocalThrottlePercent
provided you have inserted the required using lines at beginning of the script.
#52
Posted 03 May 2020 - 08:01 AM
#53
Posted 03 May 2020 - 09:26 AM
#54
Posted 04 May 2020 - 02:01 AM
Here an example on how to save and restore some variables within the script.
public override void HandleEvent(TCSEvent evt, string message) { if (message == String.Empty) { switch (evt) { ...... case TCSEvent.Save: SaveInt32((int)SSBState); SaveInt32((int)SCMTState); SaveInt32((int)RSCState); SaveInt32((int)RSCCode); SaveBoolean(RSCPresent); SaveSingle(normalSignalDistanceM); break; case TCSEvent.Restore: SSBState = (SSBSTATE)ReadInt32(); SCMTState = (SCMTSTATE)ReadInt32(); RSCState = (RSCSTATE)ReadInt32(); RSCCode = (RSCCODE)ReadInt32(); RSCPresent = ReadBoolean(); normalSignalDistanceM = ReadSingle(); break; } } else { ..... } }
#55
Posted 04 May 2020 - 07:57 AM
Thanks!
PS: I have a feeling that even scripts for the TS2020 can't do that yet. :)