Question Key press events in Lua vessel script?

Thunder Chicken

Fine Threads since 2008
Donator
Joined
Mar 22, 2008
Messages
4,367
Reaction score
3,302
Points
138
Location
Massachusetts
I am trying to figure out how to implement key presses inside a vessel script. In particular, I'd like to trigger a landing gear animation by hitting the 'G' key.

In Lua there does not seem to be a callback function for this. There is a v:send_bufferedkey(keycode) method, but I am not quite sure what it does and where it should be located.

In a C++ module I had code to do this as follows in clbkConsumeBufferedKey:

C++:
    case OAPI_KEY_G: // Gear

        //gear_anim_status: 0 - stationary, 1 - raising, 2 - lowering

        if (gear_anim_status == 0 && gear_anim_state < 1.0) // if fully or partially extended
        {
            gear_anim_status = 1; //raise gear
        }

        else if (gear_anim_status == 0 && gear_anim_state == 1.0) //if fully retracted
        {
            gear_anim_status = 2; //lower gear
        }

        else if (gear_anim_status == 1) //if raising gear
        {
            gear_anim_status = 2; //lower gear
        }

        else if (gear_anim_status == 2) //if lowering gear
        {
            gear_anim_status = 1; //raise canopy
        }

        else
        {
            gear_anim_status = 0;
        }

        return 1;

I saw this thread but am not sure if this is the answer to my problem.
 
Top