Thrusters.lua issues

Discussion in 'Programming' started by Occam's Razer, Jan 22, 2016.

  1. Occam's Razer

    Occam's Razer
    Expand Collapse

    Joined:
    Aug 7, 2013
    Messages:
    1,152
    To the tune of most of the aircraft that have been added to the game, I'm attempting to activate thrusters by way of Lua. I'll likely have problems throughout this process, but first thing's first.

    When I initially create a file called 'thrusters.lua' I get an error by way of the console saying

    Code:
    libbeamng.object|lua/vehicle/drivetrain.lua225: attempt to perform arithmetic on field 'parkingbrake' (a nil value)
    ...regardless of what the file contains. Now, I'm going to imagine that in order to do what I'm trying to do, the file must be named 'thrusters.lua.' Am I wrong, and can call it whatever I like, or is it necessary to call the file 'thrusters?' And if the latter, how do I keep the code from triggering this error and locking up all of the inputs?
     
  2. CarlosAir

    CarlosAir
    Expand Collapse

    Joined:
    Nov 16, 2013
    Messages:
    336
    You can't just create a new thrusters.lua file on your vehicle's folder, (by naming a lua file "thrusters", what you are doing is replacing the default thrusters.lua file BeamNG has, with your own one). So BeamNG already has a thrusters.lua file, but instead it is running yours now. But probably your thrusters file doesn't have all the stuff the original file had, so you might be kind of breaking the game here :p i.e. The game is looking for specific content inside the thrusters.lua file, but it's not there any more. Without any more info, I'm guessing something like this might be the cause. When replacing default lua files, you need to be very careful :p.

    Now, I recommend you avoid replacing default lua files, as it's kind of bad practice when there are other ways available, as it might break after an update (has happened to my stuff more than once :p), as devs might change the original lua files. So, it's always better to make your own lua file, completely independent from what the default files do, or stop doing.

    There are certainly times where replacing it's the only option, but specially since recently custom inputs were introduced, it's less needed. I've been able to migrate my planes to completely stop replacing default lua files.

    If you still want to use your own version of thrusters.lua, start by copying the original one (*beamngsteamfolder*/lua/vehicle/) to your own vehicle's folder, and progressively make changes to that, to meet your needs.

    Otherwise, use the other methods that don't replace default files. If you need help with that let me know.
     
    • Like Like x 1
  3. Diamondback

    Diamondback
    Expand Collapse
    Vehicle Systems Lead
    BeamNG Team

    Joined:
    Apr 8, 2014
    Messages:
    1,957
    When you just want to have a custom lua file that does something, have a look at the vehicle specific lua files of some of the stock cars (Sunburst, SBR, AWS Pessima, etc). You can see how they are set up there. And yes, your custom lua file can have *any* name, just try to avoid replacing existing files as Carlos said ;)

    Oh and if you just want to apply some force somewhere (which is basically what thrusters do), have a look at this code:
    Code:
    obj:applyForce(node1, node2, force)
     
    • Like Like x 1
  4. Occam's Razer

    Occam's Razer
    Expand Collapse

    Joined:
    Aug 7, 2013
    Messages:
    1,152
    Thank you all for your replies. So, the gist of it that I'm getting is that I'm overwriting a file default to BeamNG's programming, without adding back the code that I'm supplanting. And that my file may be called whatever I like in order to function. Okay, seems straightforward enough.

    Oh, I know about the new custom inputs. In fact, I used them on this same vehicle and they're a godsend, but I need a custom throttle system that allows for a gradient input. The ability to set the vehicle's throttle incrementally. So I should probably change the name of this thread...

    Anyway, I'll change the file's name and get to work on its content. Based upon my infirm knowledge of programming, mind.
    --- Post updated ---
    I've got the throttle more or less working, but what exactly is the difference between "applyForce" and a thruster?

    Using thrusters, I can get the propeller up to a great speed with light shaking, and using the throttle I can get it to a nominal speed with downright awful shaking. Seeing as the throttle isn't even powerful enough to lift the aircraft off the ground, but is tearing the vehicle apart, I'm going to need to assess my options again.
     
  5. CarlosAir

    CarlosAir
    Expand Collapse

    Joined:
    Nov 16, 2013
    Messages:
    336
    When using a thruster, beamng is making use of the thrusters.lua file, and the only thing that file is doing is calling "obj:applyForce(node1, node2, force)". Why the same function produces different results depending on where is it being called from?
    The update() in thrusters.lua is being called a lot more times per second than your custom updateGFX(). So, when using jbeam thrusters, obj:applyForce is being called a lot more often each second, thus the propeller spins faster (and also reduces vibration¿?).

    I suggest you consider using the following approach (which combines the best of both):
    Use jbeam thrusters, but in {"control": ""}, put the name of your (custom) throttle electrics input. And you can further tweak that variable in your own lua file. So you are using thrusters whose force is controlled by your custom gradient input.
     
    • Like Like x 1
  6. Occam's Razer

    Occam's Razer
    Expand Collapse

    Joined:
    Aug 7, 2013
    Messages:
    1,152
    Thank you, that made it. A few quick tricks, and this works perfectly.
     
  7. ThreeDTech21

    ThreeDTech21
    Expand Collapse

    Joined:
    Sep 27, 2013
    Messages:
    1,616
    Just checking out this thread, I want to learn more about lua coding. So I gathered that it's possible to create your own lua coding? For example I want to create a custom light that blinks 3 times and then stops when The letter "V" is pressed on the keyboard < your saying that I can create that if I know lua coding?

    Also I want to make a setting where a crash automatically slows the physics down to 4x speed for a duration of 5 seconds the returns to normal speed. So when a certain break group is broken then the code would start.

    It would look sometime like this:

    Break group: ["nl1:nl2"] = slow physics 4x, duration 0.05, speed physics 1x, end.

    The above is not meant to be the actual code just a relative visual of what the code would represent.

    So that is also possible through lua coding?
     
  8. Diamondback

    Diamondback
    Expand Collapse
    Vehicle Systems Lead
    BeamNG Team

    Joined:
    Apr 8, 2014
    Messages:
    1,957
    Yes, all of that is possible.
     
  9. ThreeDTech21

    ThreeDTech21
    Expand Collapse

    Joined:
    Sep 27, 2013
    Messages:
    1,616
    Excellent, where can I find a complete lua reference of commands? Or would it be better to look at the existing code being used in BeamNG lua?

    For example for the Beam break slow motion setting, should I look at the code that activities the break group system and work with that?
     
  10. Diamondback

    Diamondback
    Expand Collapse
    Vehicle Systems Lead
    BeamNG Team

    Joined:
    Apr 8, 2014
    Messages:
    1,957
    Unfortunately, there really isn't any/much documentation of the lua subsystem... :(

    Yep, exactly, that's your best bet at this point.
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice