Has Someone Got A Full List On How To Script?

Discussion in 'General Discussion' started by cityrail-rulez, Sep 10, 2023.

  1. I'm looking for a full list on how to write lua scripts as well as other scripts within the blueprint editor. Fair enough, I've got no issues creating water blueprints, importing locomotives and rolling stock as well as scenery models into TS Classic. But I've got absolutely no knowledge how to write the scripts for locomotives and rolling stock such as the scripting required for pantographs, doors, mirrors and other things, yet alone I don't even know how to use TS Tools to open other scripts to learn from them.

    I really don't want to quit on the Australian locos and rolling stock, I have added in TS Classic :( Even though they do work in the sim but I've used the developer examples and need to know how exactly to write the scripts even one that I can somehow tell the game the locomotive is in kph and not mph, just an example!
     
  2. 749006

    749006 Well-Known Member

    Joined:
    Dec 10, 2016
    Messages:
    10,033
    Likes Received:
    3,138
    Matthew Wilson is very talented with scripts and might be able to help
     
    • Like Like x 1
  3. Oystein

    Oystein Well-Known Member

    Joined:
    May 24, 2018
    Messages:
    265
    Likes Received:
    303
    Most stuff can be added without scripting. You can link any exterior animation to any control value in a blueprint. Its when you need advanced features scripting is needed. But when scripting you need to use virtual controls, or stay away from logic names that TS core uses to awoid conflicts.

    For speed in kph use "SpeedometerKPH" for the control value name, instead of SpeedometerMPH.
     
    • Like Like x 1
  4. cunningn#3154

    cunningn#3154 Well-Known Member

    Joined:
    Mar 22, 2023
    Messages:
    225
    Likes Received:
    298
    I have never found a guide. So your best bet is to grab an existing .lua file and look at what it does. The kuju Black5 provides a nice simple? example: Assets\Kuju\RailSimulator\RailVehicles\Steam\5MT_Black5\Default\Engine\Black5EngineScript.lua

    You will see:

    Some comments (use -- to designate a comment)

    function Initialise ()
    - this code runs once when the loco is created into the game session
    - BUT there are some elements that don't work here and need to run as a one-time in the update section

    function OnControlValueChange ( name, index, value )
    - this runs whenever a control value is changed (ie regulator is open/closed, horn sounded etc etc

    function Update ( time )
    - runs once in every frame to allow processing through time (ie changing steam/smoke effects according to settings, load etc)

    You can define your own functions and refer to them in the code
    You can 'use' and existing script by using the 'include' statement before any functions
    This link shows all of the engine-related script elements: http://tscdevdocs.co.uk/reference-manual/scripting-function-reference/engine-function-reference.html

    Writing a half decent developer guide would be a large undertaking with considerable ongoing hassle - which maybe why no one has done it.
    Once you have the hang of the basics (try turning smoke on/off to start with) then you could look at more complicated scripts. A difficulty is that people tend to hide their cleverness behind compiled lua (.out files are compiled lua scripts). Since mine aren't clever I am happy to leave them in the open - when you feel brave you could look at this:
    https://drive.google.com/file/d/1hJZEPPrv9gpyqrUvv1XCx7pqQAVntoiB/view?usp=sharing
    This is from my J19 steam loco: https://sites.google.com/site/cambridgelinesrailworks/file-cabinet/locomotives?authuser=0
    Please don't ask me to explain it - just work it through and then nick techniques that work for you (which is how I did it in the first place).

    There are, of course, several threads on UKTS forae...

    PS - if anyone knows of such a guide then please tell us - I'd love to have one!
     
    • Like Like x 3
  5. I think we all need a guide for scripting :)
     
    • Like Like x 1
  6. dolanbaker

    dolanbaker Active Member

    Joined:
    Dec 29, 2022
    Messages:
    144
    Likes Received:
    120
    Thanks Neil, I will have a look at some of yhe scrips as I want to create a lua script to match RPM to gear on a railbus I am making, it probably helps if you're already an experienced programmer as scripting in lua is similar to many other modern languages. It's the integration with the TSC functions that's the hard bit.
     
    • Like Like x 1
  7. cunningn#3154

    cunningn#3154 Well-Known Member

    Joined:
    Mar 22, 2023
    Messages:
    225
    Likes Received:
    298
    Agreed - the function list is a starter but there are often nuances that take some trial and error to understand (plus some undocumented stuff like the 'AddTenderWater' function that was specially added to enable Pete to do the Riviera line water troughs).
     
    • Like Like x 1
    • Helpful Helpful x 1
  8. To be honest, I wouldn't had known scripting would be involved to add water to Steam locomotive tenders. After I got the NR, XPT, QR ICE, Adelaide Metro 3000/3100 and Adelaide Metro 4000 Class sorted with scripting I was going to add a first Australian Steam locomotive into TSC and I wasn't sure if the water for the tenders were scripted or just added to the blueprint. Thanks for letting me know :)
     
    • Like Like x 1
  9. cunningn#3154

    cunningn#3154 Well-Known Member

    Joined:
    Mar 22, 2023
    Messages:
    225
    Likes Received:
    298
    In normal usage the water in the tender isn't an issue - the game handles it for you (as long as you remember to fill up from a suitable water tower etc). That specific function is necessary to enable water troughs which were an innovation in the Riviera Line route when it was released a few years ago.
     
    • Like Like x 1
  10. Oystein

    Oystein Well-Known Member

    Joined:
    May 24, 2018
    Messages:
    265
    Likes Received:
    303
    No scripting is required to make a train work in TSC with basic functions.
    Make a plan for what functions you want to have, then figure out what TSC can do and what needs to be scripted. If this is your first train for TSC I wouldn't bother with scripting anything unless you feel that a missing feature is very important to have. If you overcomplicate the project you will just end up never releasing it (speaking from experience :))
     
    • Like Like x 1
  11. Ah yes, I
    I originally contacted DTG for some issues I have with a pantograph, they told me that scripting is required as well as setting up the input mapper. They haven't gotten back to me yet as DTG was planning to send me examples of scripts for Steam, Electric 'Panto on trailer car, panto on driving car and electric locomotive dual panto and single panto and of course some scripting for diesels, doors and other stuff...

    I got impatient as I haven't heard back from DTG, so I thought about asking here :)
    It's not my first train I've imported into TSC! I originally imported my own NSW 86 Class Electric Locomotive, I couldn't get the thing to move at all HAHAHA But I never gave up trying, the first thing I was successful getting it to move is the NSW XPT engine itself followed by the NR Class locomotive. I also need scripting for setting up different liveries... I think? Not really sure!
     
  12. Oystein

    Oystein Well-Known Member

    Joined:
    May 24, 2018
    Messages:
    265
    Likes Received:
    303
    I recommend the Train Sim Modding server on Discord, I don't have the direct invite link for it but you should be able to find it on the community site https://www.trainsimcommunity.com/
    There are lots of helpful people on there that share their knowledge about TS modding, including script examples.
     
    • Like Like x 2
  13. I don't have discord so that's not going to be much helpful! I'll just contact DTG and see if they could help.
     

Share This Page