Post Reply 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Detect key pressed
2017-09-11, 06:17 PM
Post: #1
Detect key pressed
My Lua scripts have evolved well, but now i find my self needing to give user input to them. Here are some examples.

Key to detonate already launched missiles if target is standing down (to allow capture).
Keys to change desired altitude on my air ship. I have a script that controls all my thrusters and maintains altitude relative to water or terrain, i want a key to change that value.

So, how do i detect that a key is pressed?
Please only LUA related solutions.
Find all posts by this user
Quote this message in a reply
2017-09-12, 05:27 AM
Post: #2
RE: Detect key pressed
I haven't dug into 2.0 much yet, but I don't believe there's a direct way to get keypresses. However, there are a number of roundabout ways to go about creating a "switch" you can trigger with a key. The component API has access to a number of devices, which Lua can both read from/write to: balloons, pumps, tractor beams, etc. Look at the Component_* methods, specifically.

Set up a complex controller, bind keys to the device, read the state from Lua. Since you access most things in Lua via their index, distinguishing between which ones are your control and which ones aren't is left as an exercise. Wink (I typically use the direction that the block is facing...)

As for manual altitude control, I think the best option is the drive maintainer. Because:
  1. It's analog and lets you go smoothly from -1 to 1
  2. You can reset it to 0 by hitting your increase/decrease keys simultaneously (just like throttle on water craft)
  3. You can display the current value on the HUD by enabling it in options (primary, secondary, tertiary drive).
Pretty much all of my aircraft & submarine scripts allow optional manual control via drive maintainer. It's really nice.

My Workshop | My FtD Lua Scripts
Find all posts by this user
Quote this message in a reply
Post Reply 

Forum Jump:

User(s) browsing this thread: 1 Guest(s)