Fixed crashing when not passing negative key
This commit is contained in:
parent
546f3a562e
commit
4450fa1c83
@ -27,7 +27,13 @@ function Input:noKeysHolding(axle)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function Input:getAxleValue(axle)
|
function Input:getAxleValue(axle)
|
||||||
return (input.isKeyDown(axle.Positive) and 1 or 0) - (input.isKeyDown(axle.Negative) and 1 or 0)
|
local positiveValue = axle.Positive ~= nil and input.isKeyDown(axle.Positive)
|
||||||
|
local negativeValue = axle.Negative ~= nil and input.isKeyDown(axle.Negative)
|
||||||
|
|
||||||
|
print(positiveValue)
|
||||||
|
print(negativeValue)
|
||||||
|
|
||||||
|
return (positiveValue and 1 or 0) - (negativeValue and 1 or 0) -- (input.isKeyDown(axle.Positive) and 1 or 0) - (input.isKeyDown(axle.Negative) and 1 or 0)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Input:_trySetTargetValue(key)
|
function Input:_trySetTargetValue(key)
|
||||||
@ -52,14 +58,19 @@ end
|
|||||||
|
|
||||||
function Input:_mapKeys(axles)
|
function Input:_mapKeys(axles)
|
||||||
for k, v in pairs(axles) do
|
for k, v in pairs(axles) do
|
||||||
|
if v.Negative ~= nil then
|
||||||
self.keys[v.Negative] = {
|
self.keys[v.Negative] = {
|
||||||
Axle = k
|
Axle = k
|
||||||
}
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
if v.Positive ~= nil then
|
||||||
self.keys[v.Positive] = {
|
self.keys[v.Positive] = {
|
||||||
Axle = k
|
Axle = k
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Public here
|
-- Public here
|
||||||
|
|||||||
13
koptilnya/input_system/configs/sample.txt
Normal file
13
koptilnya/input_system/configs/sample.txt
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
Axles = {
|
||||||
|
Horizontal = {
|
||||||
|
Negative = KEY.D,
|
||||||
|
Positive = KEY.A,
|
||||||
|
Gravity = 0.1,
|
||||||
|
Sensitivity = 0.2
|
||||||
|
},
|
||||||
|
Throttle = {
|
||||||
|
Positive = KEY.W,
|
||||||
|
Gravity = 0.1,
|
||||||
|
Sensitivity = 0.2
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -3,14 +3,8 @@
|
|||||||
-- @shared
|
-- @shared
|
||||||
-- @include ./cl_input.txt
|
-- @include ./cl_input.txt
|
||||||
-- @include ./sv_input.txt
|
-- @include ./sv_input.txt
|
||||||
local Axles = {
|
-- @include ./configs/sample.txt
|
||||||
Horizontal = {
|
require('./configs/sample.txt')
|
||||||
Negative = KEY.D,
|
|
||||||
Positive = KEY.A,
|
|
||||||
Gravity = 0.1,
|
|
||||||
Sensitivity = 0.2
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
local options = {
|
local options = {
|
||||||
Axles = Axles
|
Axles = Axles
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user