LOTUS NG Rust script: Sound Source consumes Play command but no sound is played

  • Hello,

    I am currently converting an existing bus from classic LOTUS to LOTUS NG and I have encountered a problem with a looping engine Sound Source.

    The vehicle script is written in Rust using lotussim-script 0.8.5.

    The Sound Source is configured as follows in the Object & Vehicle Tool:

    ENGINE_PLAY -> BMB240L_Sound_Engine
    ENGINE_RPM -> Engine_n_RPM
    In the Sounds Tool:

    Playback control variable: ENGINE_PLAY 1 = Play
    -1 = Stop

    Playback speed/pitch variable: ENGINE_RPM
    Normal playback value: 0.575
    Loop until the control variable is set to -1: enabled
    The RPM variable works correctly. The Rust script writes:

    var::set_var("Engine_n_RPM", self.engine_rpm / 1000.0);
    For example, Script Debug shows:

    Engine_n_RPM = 0.628994...
    ND313_NG_EngineRPM = 628.994...
    so the RPM mapping and scaling are working.

    The audio file and the Sound Source itself also work. If I remove the ENGINE_PLAY control variable from the sound definition, the engine sound plays continuously in LOTUS NG, including when the engine is switched off.

    I also tested the Sound Source manually in the Content Tool/Test Script. With:

    Engine_n_RPM = 0.575
    BMB240L_Sound_Engine = 1
    the engine sound starts correctly. The Play variable then returns automatically to 0, as expected.

    The problem occurs when the same Play command is generated by the NG Rust script.

    We tested:

    var::set_var("BMB240L_Sound_Engine", 1_i64);
    We also verified that integer and floating-point variables written with var::set_var() reach LOTUS correctly by writing diagnostic variables:

    var::set_var("BMB240L_TEST_INTEGER", 12345_i64);
    var::set_var("BMB240L_TEST_FLOAT", 12345.0_f64);
    Both appear correctly in Script Debug as 12345.

    We then performed a readback test immediately after writing the Play command:

    var::set_var("BMB240L_Sound_Engine", 1_i64);
    let value = var::get_var::<i64>("BMB240L_Sound_Engine");
    The immediate readback was 1.

    Finally, we performed a “write once” test: the Rust script writes 1 only once when the engine changes from OFF to ON and does not write to BMB240L_Sound_Engine again. On subsequent simulation frames we only read the variable.

    The result is:

    command sent = 1
    later readback = 0
    Therefore LOTUS appears to receive and consume the Play command and automatically resets the variable from 1 to 0.

    However, the sound remains completely silent.

    We have also tried:

    i32 and i64 (both ultimately use set_i64 in lotussim-script)
    writing 1 continuously
    a one-frame 0 -> 1 -> 0 pulse
    writing Play only on the engine OFF -> ON transition
    different RPM tests, including the known-working value 0.575
    None of these starts the sound from the Rust script.

    So at the moment the behaviour is:

    Content Tool/Test Script:
    BMB240L_Sound_Engine = 1
    -> command consumed/reset to 0
    -> sound starts

    LOTUS NG Rust script:
    BMB240L_Sound_Engine = 1
    -> command consumed/reset to 0
    -> NO sound
    Is there a special requirement in LOTUS NG for triggering a Sound Source Play/Stop variable from a Rust/WASM script?

    In particular, is var::set_var("...", 1_i64) supposed to be sufficient for a Sound Source control variable, or does NG require an observer/change/event mechanism for Play/Stop commands?

    I noticed that the current GT6N NG example uses constructs such as loop_sound() / start_loop_stop_sound() through lotus-rt-extra, but that library does not appear to be publicly available. Is this related to the issue, or should the classic Sound Source variable mechanism work directly with lotus_script::var::set_var()?

    Any clarification about the intended way to trigger Play/Stop Sound Source variables from an NG Rust script would be very helpful.

    Thank you!

  • Hallo!


    Sorry for letting you test and write so much...


    But the answer is very easy: In NG, the sound play control variable has to be of type "bool"... setting it to "true" => Sound starts, "false" => Sound stops. After setting and after the sounds has "used" it, the variable will vanish.

  • Newly created posts will remain inaccessible for others until approved by a moderator.

    The maximum number of attachments: 5
    Maximum File Size: 500 kB
    Allowed extensions: bmp, cfg, ini, jpeg, jpg, lct, ldl, llg, lob, log, lpmtl, lptmt, ltx, pas, pdf, png, railtrack, rar, txt, veh, wav