script doesn't work

er9m

Member
Hello, can anyone tell me, please, why this script doesn't work? There are no errors, but locomotive shutters animation doesn't work. I added all tags in config the same as they are in script, also added necessary sounds. Here is script:

 
Code:
include "Locomotive.gs"

class ZLocomotiveLLCType2 isclass Locomotive {
    
    bool FanState = false;
    Asset MyAsset1;

    public void Init(Asset asset) {
        inherited(asset);
        MyAsset1 = asset;
        
        SetMeshAnimationState("galuzi_vody_right", false);
        SetMeshAnimationState("galuzi_vody_left", false);
        SetMeshAnimationState("galuzi1_verhnie", false);

        AddHandler(me, "Vehicle", "Throttle-Change", "OnThrottleChanged");
    }

    void OnThrottleChanged(Message msg) {
        float throttle = GetEngineSetting("throttle");

        if (!FanState and GetEngineSetting("throttle")>5) {
            FanState = true;
            World.PlaySound(MyAsset1, "sound/zhaluzi_on.wav", 1.0f, 20.0f, 100.0f, me, "a.zhaluzi");
            Sleep(0.1);
            SetMeshAnimationState("galuzi_vody_right", true);
            SetMeshAnimationState("galuzi_vody_left", true);
            SetMeshAnimationState("galuzi1_verhnie", true);
        }
        else if (FanState and GetEngineSetting("throttle")==0) {
            FanState = false;
            World.PlaySound(MyAsset1, "sound/zhaluzi_off.wav", 1.0f, 20.0f, 100.0f, me, "a.zhaluzi");
            Sleep(0.1);
            SetMeshAnimationState("galuzi_vody_right", false);
            SetMeshAnimationState("galuzi_vody_left", false);
            SetMeshAnimationState("galuzi1_verhnie", false);
        }
    }
};
 
There are no errors, only warnings and they all are common with locomotive mesh, but not with script. When i drive locomotive with another script - animation works. But the problem is that - another script doesn't fit to me, so i decided to make my own.
 
Last edited:
Hello, can anyone tell me, please, why this script doesn't work? There are no errors, but locomotive shutters animation doesn't work. I added all tags in config the same as they are in script, also added necessary sounds. Here is script:

...
According to the WiKi on this page , that message is sent by the Train and not the Vehicle. The message is actually "ThrottleChanged" so your script would have to listen (Sniff) for messages sent by your train.

I ran a small test session and couldn't see any such messages in the log in any driving mode. So, I wonder if the message does exist as a standard message. Others may know more.

You could write you own throttle monitor code or use one in some library included by your script.

BTW, if the animated meshes didn't exist in the model Trainz would simply ignore the animation call so there would be no error messages. That may change in future validation checks.
 
According to the WiKi on this page , that message is sent by the Train and not the Vehicle. The message is actually "ThrottleChanged" so your script would have to listen (Sniff) for messages sent by your train.

I ran a small test session and couldn't see any such messages in the log in any driving mode. So, I wonder if the message does exist as a standard message. Others may know more.

You could write you own throttle monitor code or use one in some library included by your script.

BTW, if the animated meshes didn't exist in the model Trainz would simply ignore the animation call so there would be no error messages. That may change in future validation checks.
Well, i'm not keen on scripts, so i don't know, how to get those messages coming or how to write throttle monitor code.
 
Here is a rewrite that may help. Note that it doesn't include any coupling functionality, numbers, etc. I haven't compiled or tested it. If there are compile issues then DM me with the errors.

C-like:
include "Locomotive.gs"

class ZLocomotiveLLCType2 isclass Locomotive {
    
bool FanState = false;
bool objectRunningDriver = false;
    
// prototypes
    
thread void MainThread();
void ModuleInitHandler(Message msg);
  

public void Init(Asset asset) {
  inherited(asset);
 
  SetMeshAnimationState("galuzi_vody_right", false);
  SetMeshAnimationState("galuzi_vody_left", false);
  SetMeshAnimationState("galuzi1_verhnie", false);
}

    
void ModuleInitHandler(Message msg) {
  if (objectRunningDriver) {
      return;
  }
    
  if (World.GetCurrentModule() == World.DRIVER_MODULE) {
    objectRunningDriver = true;
    MainThread();
  }
}


thread void MainThread() {

    while(true) {

        if(!FanState and GetEngineSetting("throttle")>5) {
            FanState=true;
            World.PlaySound(MyAsset1, "sound/zhaluzi_on.wav", 1.0f, 20.0f, 100.0f, me, "a.zhaluzi");
        }
        
        if(FanState and GetEngineSetting("throttle")==0) {
            FanState=false;
            World.PlaySound(MyAsset1, "sound/zhaluzi_off.wav", 1.0f, 20.0f, 100.0f, me, "a.zhaluzi");
        }
        
        SetMeshAnimationState("galuzi_vody_right",FanState);
        SetMeshAnimationState("galuzi_vody_left",FanState);
        SetMeshAnimationState("galuzi1_verhnie",FanState);
        Sleep(5.0);
    }
}

};
 
Back
Top