Trainz Script Library

VVMM

Trainz Scripter/Developer
Hi!

I have created a lot of assets that all share a common script. How can create a separate KIND Library asset and make all the other assets load their script from the Library asset? I read something about a script-inlude-table from online.ts2009.com, but i don't know how can i use it. It is very annoying to manually copy the script to all assets whenever modified.

Thank you.
 
It is very annoying to manually copy the script to all assets whenever modified.
even if you're using script-inlude-table, you should add a script to your add-onn (and specify there a link to "base" script file, located in the library).

So, it is impossible to remove scripts from an asset completly.
 
yes but that script need only reference the original library script and nothing else, thus not requiring an update each time.

it is quite difficult for me to explain this for some reason, but have your asset's script set as you would any regular script. for example myscript.gs.

inside myscript.gs would be:

Code:
include "mylibrary.gs"

class MyAsset isclass someClassName
{
}

put script-inlude-table in the config referencing your library asset.

then for your script, put it in the library asset as mylibrary.gs with the class someClassName in it. this would be the normal class you used to use from the config. for example, say you are making a signal library inside mylibrary.gs would be

Code:
include "Signal.gs"
include	"Library.gs"


class Mylibrary isclass Library{};

//below is where you can place the old script, or it can even be another .gs file in the library asset, you can have as many as you want.

class someClassName isclass Signal
{
  //all your script code goes here
}

clear as mud yet?
 
Can you provide a code example?

As far as I know the script you place in the asset is a simple one.
Code:
include "my_script_library_script_filename.gs"

something isclass whatever {

};

But I'm not sure what the correct entries are. When I've tried this, I got errors that class "whatever" was undefined, and I gave up.
 
"whatever" must be a defined class somewhere.

in my example above i use "someClassName"

i defined "someClassName" as a class "Signal" later on which is a trainz base class. this was defined in the library asset, but it could be in any .gs file this asset can reach. in the end, any class not defined as static must be an already defined class.
 
Thank you for explanations, norfolksouthern37, but unfortunately it gives me the following error: Unable to link compiled scripts.

Here is the script that is included in every signal (ssemnal.gs):
Code:
include "semnal.gs"

class SSemnal isclass Semnal
{
};

Here is part of the script that resides in the library (semnal.gs):
Code:
include "Signal.gs"
include "Junction.gs"
...
include "Library.gs"

class MyLib isclass Library {};

class Semnal isclass Signal
{

...

};

Later edit: Hmmm... it it just weird... I restared my computer and now the script works, no errors... :o
 
Last edited:
"whatever" must be a defined class somewhere.

in my example above i use "someClassName"

i defined "someClassName" as a class "Signal" later on which is a trainz base class. this was defined in the library asset, but it could be in any .gs file this asset can reach. in the end, any class not defined as static must be an already defined class.

Sorry NS37, your post hadn't appeared when I wrote mine. Your explanation as it turns out is pretty much what I was asking for...
 
You have a thread on this already, don't you? Or at least something along those lines down in the Scripting section of the forum? Was there a reason to bump a four-year-old thread for one question when you already have a thread dealing with scripting?
 
Back
Top