How can I get a script to do this?

frogpipe

Yesterdayz Trainz Member
I have a signal, and it has an attached name board.

What I want to do is this:

Code:
if (a name has been set) {
     make mesh visible;
}else{
     make mesh invisible;
}

I briefly thought that I could use soup to get the name value, but then realized that it was just checking if there was a value set in the config file... I need to know if someone sets a name for it in surveyor.
 
My wild guess is that you are going to need to add a script to your asset. To do so, you need to add something like this to the config file:
Code:
script                                  "myScript.gs"
class                                   "myScript"

Of course you will then also have to add this .gs file to your asset for it to work.
To check the name of a vehicle or consist, you will need one of these two to that file:
Code:
train.GetTrainDisplayName()
train.GetFrontmostLocomotiveVehicle().GetName()

I have no clue how to show or not show something with code.

For future script questions, please post here:
http://forums.auran.com/trainz/forumdisplay.php?23-Scenario-Scripting-amp-Scriptlets
 
Well on my way. Another round of slamming my face into the briki-wall yielded GetName() - I already knew the SetMeshVisible() so I'm on my way!

EDIT:

Code:
  /* Checks if the signal has an assigned name (number)
   * and sets the number board to be visible if it does.
   * If name is removed, then board becomes invisible.
   * -- T. Thompson
   */

  void NumberboardVisibility() {
    
    string MyName = GetName();
    
    if (MyName != "") { 
        SetMeshVisible("standard-number-board",true,0.0);
    } else {
        SetMeshVisible("standard-number-board",false,0.0);
    }
  }
 
Last edited:
well i guess the only trouble would be that a signal with a number board has an entirely different function than one without.

whats on the 'number board'?
how can you name a signal without the 'number board' showing?

you should probably set it up to use a link in the surveyor dialog rather than relying on the name set there.
 
Back
Top