Jump to content
The simFlight Network Forums

Overriding functions in a separate Lua script


Recommended Posts

Hi there, long time no see! Hope you're doing great, Pete. 
So I'm planning to go back to doing some flight simming after a long hiatus. Got some new gear and I'm in the process of configuring everything in FSUIPC/LINDA.
 

I have a Lua script to map the flaps, spoilers and gear lever to a single axis using ranges. The idea is to push the lever all the way up/down to retract/deploy the gear, while a smaller input to the lever increments or decrements the flaps. Then I use the global shift utility in LINDA to duplicate that for the spoilers.

I have a Lua script to take care of all that called lindaDefault.lua, which works well for aircrafts that use default controls for the gear, flaps and spoilers.

The plan is to then use specific scripts for planes that require some custom logic for some or all the controls. These scripts execute a require('lindaDefault') so that they have access to all the default functions there, and then I can (hopefully) override the functions that are needed to make the script work for that specific plane. For example, the NGX uses different controls for the spoilers, so I would be overrinding those functions while using the default ones for the flaps and gear.

This is a snippet of lindaDefault.lua, containing one of the functions - spoilersDeploy() - that are meant to be overriden if necessary. 

[code]

-------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------- OVERRIDABLE FUNCTIONS ---------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------

function spoilersDeploy() 
    ipc.control(66064) -- Spoilers Deploy
end

-------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------

function AXIS_GEAR_SPOILERS_100() 
    if SHIFT_GLOB == 0 then
        ipc.control(66080) -- Gear down
    else
        spoilersDeploy()
    end
    ipc.set('LEVER_MAXED_OUT', true)
end

FUNCTIONS =
{
  [1] = AXIS_PARKINGBRAKES_SPOILERS_OFF,
  [2] = AXIS_PARKINGBRAKES_SPOILERS_ON_ARM,
  [3] = VOID,
  [4] = AXIS_FLAPS_SPOILERS_DEC,
  [5] = AXIS_FLAPS_SPOILERS_INC,
  [6] = AXIS_GEAR_SPOILERS_0,
  [7] = AXIS_GEAR_SPOILERS_100,
}

func = FUNCTIONS[f]

if (func) then
    func()
else
    ipc.log('nope, no function here to be called')
end

[/code]

Then I have this lindaNGX.lua that's supposed to override the spoiler functions like this:

[code]

require('lindaDefault')

-------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------- OVERRIDABLE FUNCTIONS ---------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------

function spoilersDeploy() 
    ipc.control(86637, 16384) -- Spoilers Deploy
end

function spoilersRetract() 
    ipc.control(86637, -16384) -- Spoilers Retract
end

function spoilersArm() 
    ipc.control(86637, -13100) -- Spoilers Arm
end

function spoilersDisarm() 
    spoilersRetract()
end

-------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------

[/code]

 

This is not working. The functions in lindaDefault.lua are the ones being called.
Any ideas, please? Thanks in advance.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.