LOTUS NG scripting

  • I'm trying to figure out the new scripting system, which is not easy since the only documentation about the vehicle scripts...are the scripts themselves, which literally have no comments in it. Anyway, since I cannot find out how could I resolve the dependency problems, I tried to build the given GT6N scripts, thinking surely I forget something. Well nope, or I don't know:



    Even the given GTN cannot be built (https://github.com/Oriolus-Sof…t6n/tree/observer_version). What am I missing, how could I reach these crates/whatever these are called (lotus_extra, lotus_rt_extra...etc)?

  • Hello!

    Thanks for the response!
    I've seen this information page, I installed rust and the lotus-sc based on it.


    Also, based on it I can use the basic lotus-script crate. But how can I use the other crates (if I'm right) like lotus-rt-extra and lotus-rt? It seems to be, looking at the GT6N scripts, that many default things are collected from them.


    I see on the crates.io page, that there are other crates with the name lotus-*. I guess the ones for LOTUS are the ones made by Ekranos and you, right? Which one of them do I/we need for vehicle and other objects? lotus-extra and lotus-rt are my guesses.

    I tried to install `lotus-rt`, but it didn't work out:


    I also tried to add lotus-rt-extra to my project but that also didn't work:


    How could I install these crates?

  • Also some things I forgot to ask which I don't really find in the docs:


    What's the "main" script file the compiler looks for, `lib.rs` (like the Main.pas in the old version)? How do I link the files? I see in the TG6N that in the lib.rs file all other used files are added as modules (pub mod xyz), but I also see that in every script file, other script files are loaded with the use directive.


    Do we have to declare public variables like in the old version (PUB_VARS) or we just start to use them with get_var and set_var? The latter seems to be the case as I could add some variables to my tram. But there's some info in one of the docs.io page, stating an example like:

    impl PublicVarType for bool. How can we make non-public variables? With the directive let?


    Are there any summary about the usable base variables, structs...etc? Is the docs.io page the correct way to look for these, like this page for the `lotus-extra` crate? I looked at most of these and I still cannot find stuff used in the GT6N, like lotus_rt_extra::cockpit_simple::...

  • Hello!


    My GT6N script uses different programming principles that are not yet fully completed and/or documented. For this reason, the two crates are not yet available and the GT6N crate cannot yet be compiled.


    However, I will create an introductory tutorial in which I explain some of the basics in a “classic” way using an example.


    So I hope you can bear with me a little longer! :-)

  • I have one issue I cannot solve, and it's driving me nuts: how should we implement global variables? I'm not talking about public vars (which are later used by sounds/animations/lights...etc), I mean inner variables that are used in multiple files (like electronics, cockpit, doors...etc).


    Should I just don't care and put all of them as public vars? At the moment I did, so I can continue porting the script, but I'd like to know if there's any other good practice.


    Also one thing I'd like to ask: is there any way to alter texture maps, like with `GetTextureIndex` with the old engine? Is there any implemented way for that?

  • Regarding global variables: There are no global variables in Rust. In the classic approach, the “global” variables are located directly or indirectly in the script struct (in a new project, this is called “MyScript”), e.g., in sub-structs, e.g., for doors, which are then included as a field in the script struct.


    Have you read the Rust book?
    The Rust Programming Language - The Rust Programming Language


    Regarding texture swapping in particular: I know there are still gaps in the documentation, so please wait.

  • I'm starting to figure out things, but another, full random thing came across:


    I looked at the function declaration and it seems this push function always needs two arguments. Is there a way to _not_ add a key for a custom bind? Like a cab has dozens of clickable elements, and I don't think the intended usage is to have millions of keyboard bindings after installing a few vehicles. Or is this a temporary state until users can setup their own bindings?

  • Hello!


    Usually in most cases, you do not need this function.


    Just use:


    Code
    1. let state = action::state("Throttle");
    2. if state.kind.is_just_pressed() {
    3. log::info!("Throttle has just been pressed");
    4. }

    :-)


    You may use any string, especially those which you have used in the ContentTool.

  • Quote

    You may use any string, especially those which you have used in the ContentTool.


    Wait, so if I only use an action for some clickable elements and add them a custom name, I don't have to register that action? So this action register function is more fore things like fixed keys for given inputs?


    A few other things got me thinking. What's the best practise for polling the inputs when handling user inputs? At the moment I made something like this (very exaggerated example):



    ...and I actually handle all of the user inputs in both cockpits like this. I guess I have to call action::state("xyz") in every tick for every input, since this function returns only data for the given input.


    Is there any better way for this, or this is the correct way?

    Also I noticed the GT6N only has running sounds on the first module, and I also noticed my tram, which also has 3 modules and plays all the bogies, sounds very...strange. Am I right if I think at the moment all looping sounds are started at exactly the same time and that's the reason for the ghostly effect for running/motor sounds?

  • The action::state("something") is mostly meant as an ad-hoc way to get something up and running. It's pretty inefficient to check these states every tick. Cause the script has to pass the WASM boundary and serialization/deserialization has to happen.

    You also get an ActionEvent if any action gets triggered. See https://docs.lotus-simulator.dev/en/rust/messages/

    We are still working on how to nicely use the message system in Rust, hence we don't exactly "advertise" this way currently.


    I personally can't say anything about the sounds, sorry.

  • I figured out the GTN only changes the nighttexture brightness from script, but I still would like to know, if it's possible to change textures from script at the moment, or is this a future feature?

  • Concerning the sounds:


    Oh, this could be right, I will check this!


    Here's a little clue about what I'm talking about the sounds.


    Here's my tram at starting in the old engine:


    And here's the ported version in NG:



    I didn't alter the scripts for calculating sound curves and volumes, and I set all sound variables (so for all 4 bogies I set the electric motor and running sounds).

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

    The last reply was more than 60 days ago, this thread is most likely obsolete. It is recommended to create a new thread instead.

    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