Expand potential of TCS scripting
#71
Posted 29 May 2020 - 12:57 AM
Re the other problem I'd like to keep compatibility with existing script(s). If you find a solution that keeps such compatibility, that could be inserted in the code.
#72
Posted 30 May 2020 - 04:30 PM
if (Locomotive() is MSTSElectricLocomotive electricLocomotive)
and... it didn't work.
The CSharpCodeProvider in the framework is only compatible with C# v5 and not the latest versions (and seems like we are not using it properly according to Microsoft : we shouldn't use the CSharpCodeProvider with CreateCompiler but the CodeDomProvider.directly).
In order to support C# v7, the modifications are simple (and I tested it and it works perfectly), but the package provided by Microsoft on NuGet adds the Roslyn compiler in the final directory.(18,7 MB).
#73
Posted 08 June 2020 - 05:07 PM
When I click on it the first time, I receive GenericTCSButtonPressed. No problem.
When I click on it the second time, I receive GenericTCSButtonReleased... and GenericTCSButtonPressed after that.
Do you have any idea what could provoke this ?
#74
Posted 09 June 2020 - 12:07 AM
As of now TCS commands may be only of PRESSED type. If you have to manage a switch, you must have a PRESSED TCS control for the command, with transparent .ace, and an ONOFF TCS control (with no command) that you use for the display of the switch, and whose state is managed by the script.
Maybe a further generalization could be envisaged where, looking at the Style() of the control, different code lines are used for the command.
#75
Posted 18 June 2020 - 05:38 PM
And here's the branch for C# v7 script support (based on 64bit branch, but can be adapted easily for the official branch) : https://github.com/S.../script-csharp7
I am taking a look at the ONOFF command currently. Maybe I will be able to do something.
Edit : And... it's done. You can take a look on my repository. I did the same thing as in the CircuitBreaker commands.
#76
Posted 19 June 2020 - 12:52 PM
#77
Posted 23 July 2020 - 10:40 AM
Here's the branch with my concept of C# signal scripts: https://github.com/S...p-signal-script
Scripts would be like that: https://github.com/S...nal_Scripts_POC
Example: https://github.com/S...ter/BAPR-AVL.cs
This is a distant signal.
As you can see, one of the new concepts is the text signal aspect. You can customise the name of the aspect to fit your needs which makes it less ambiguous.
And it also facilitates the creation of more complex signal aspects (such as the ones needed for TVM430, for example : "FR_TVM430_Ve270_Vc270V_Va220").
The interface with TCS scripts in in progress.
#78
Posted 25 August 2020 - 07:31 AM
Csantucci, on 28 March 2020 - 10:21 AM, said:
Script.Locomotive = () => Locomotive;
Locomotive is the actual player locomotive.
It looks like a trivial thing, but with this the TCS script may have access to the whole Simulation environment public classes and methods (trainset, player train, signals and so on).
Therefore it is no more needed to add further personalized hooks, and only general use hooks might be added.
Hi all, I am just reading through the posts in this thread, and the above mod hit my eyes. It is a bad idea exposing such an internal object to scripts, because it may change at any time, which renders the script incompatible. A small refactoring, a change in a variable's name, or a major change for accomplishing some important thing and oops... the script is off. That is why there is a scripting interface defined. That can be guaranteed to remain in place, and its functions are always connected to the internal structure of the bigger program properly. This kind of exposing cannot be allowed from the OpenRails development perspective, looking the big picture.
#79
Posted 26 August 2020 - 11:12 AM
#80
Posted 26 August 2020 - 10:22 PM
Csantucci, on 26 August 2020 - 11:12 AM, said:
But… This is exactly the scope of this work! You have to collect the needs, and think of a system that best fits! By keeping in mind not just one possible additional script, but a generalized system.
I must say, I could think of more system-like functions for the (sorry for the word) FAQ-style additions mentioned on the first page of this thread, numbered 1-5.
(1) is too specific, got ignored, that maybe someone else needs to check other aspect types, other numbers. Instead, this function should return an array of possible aspects, and let the script writer examine whether those are the ones that he is searching for.
(2) Is always only the first next distance signal (or head) important, or the subsequent ones as well? In the latter case the pattern of the other queries should be followed, with a Func<int, float> type definition.
(3) Why aren't the distant signals collected into a common array together with the distant heads of normal signals, and this function returns the aspect of the next closer one? This way (4) and (5) would not even be needed. And this function maybe should also follow the pattern.
Designing a scripting interface is not easy. What functions does the script you mentioned need from the internal Locomotive class? A real interface must be defined for those.