SDK Question Lua vessel script learning thread

In the event that making the Terminal Console spit out better and more helpful error messages, I would suggest updating the Lua API documentation to include script examples of each API command and including more Lua script examples would be the way to go. In the script examples, everything would be commented with easy to understand comments, even for a new-comer to Lua scripting.

The examples could be divided up in the different purposes:


  • Carina type, that defines just a mesh, mass and attachment points
  • ShuttlePB type, that advances the Carina type with aerodynamics and aerodynamic control surfaces
  • Maybe, if at all possible, multistaging.
 
Last edited:
It is a whole lot better than many other embedded languages.
Syntax errors can be caught and described... luaL_loadfile fails with a non-zero return value and you have a error number and a error string on the Lua stack.

Yep, that's the link I posted above. I have seen people write complete debuggers with inline debugging capability, etc. It was hard to believe that such functionality was missing for something so widely used.
 
Check that "spot" is a valid object (at least non-nil). Check that "vi" is a valid object. For example, your call to vessel.get_focusinterface has a superfluous argument. It probably doesn't hurt, but you never know. Did you check that the focus vessel has actually any light emitters defined? If you use an invalid index, it will return nil. Did you really want the focus object, or an object called 'SSU_PLB_floodlights'? In that case, you need a different function. Always read the documentation.
Let's try to pick this up again: Which function should I use to obtain Lua script access to the Lua script vessel "SSU_PLB_floodlights"?

And it does have a light emitter defined as shown in the code pasted in below.

When I use any of the get functions, it never returns anything, just the standard start line symbol(the "%").

Screnshot of that is attached to this post.

Code:
--[[
: This LuaScript vessel is used in the interim to simulate the 6 floodlights in the payload bay
: The lights are named after their positions in the bay
ClassName = SSU_PLB_floodlights
Module = ScriptVessel
Script = SSU_PLB_floodflights.cfg
END_PARSE
--]]

-- Basic Lua script section
function clbk_setclasscaps(cfg)
  vi:set_size(22.0)
  vi:set_emptymass(0.0001)--Dry empty mass
  vi:set_pmi({x=0.0001,y=0.0001,z=0.0001})
  vi:set_crosssections({x=0.0001,y=0.0001,z=0.0001})
  vi:add_mesh('Carina')
  hattach1 = vi:create_attachment(true,{x=0.0,y=-2.5,z=0},{x=0,y=0,z=1},{x=0,y=1,z=0},'XS')
  le = vi:add_spotlight({x=-1.75,y=8.2,z=-1.32},{x=0,y=0,z=1},{range=10,att0=1e-3,att1=0,att2=2e-3,umbra=0.3,penumbra=0.5})
end
 

Attachments

  • Lua_Terminal_console_return.jpg
    Lua_Terminal_console_return.jpg
    28.1 KB · Views: 12
Some progress made at last. I have managed to make the Terminal console accept the commands:

Code:
v=vessel.get_interface('SSU_PLB')
spot=v:get_lightemitter(0)
spot:activate(true)

These are the commands needed to activate a spot light on a vessel. It of course assumes the light emitter you want to activate has the index 0. Is there any way to get the scenario to save/load the state of the light emitter?
 
... I would suggest updating the Lua API documentation to include script examples of each API command and including more Lua script examples would be the way to go. In the script examples, everything would be commented with easy to understand comments, even for a new-comer to Lua scripting.

The examples could be divided up in the different purposes:


  • Carina type, that defines just a mesh, mass and attachment points
  • ShuttlePB type, that advances the Carina type with aerodynamics and aerodynamic control surfaces
  • Maybe, if at all possible, multistaging.
Good idea, but I will have to delegate that task, because I really won't have time to do justice to that. Are you willing to take this on? I can give you the html sources for the scripting manual, unless you want to do it on a different platform (forum, wiki).
 
Good idea, but I will have to delegate that task, because I really won't have time to do justice to that. Are you willing to take this on? I can give you the html sources for the scripting manual, unless you want to do it on a different platform (forum, wiki).

I can help out with the examples, shouldn't be hard now that I know where the documentation is :thumbup: Orbiter wiki ?
 
Back
Top