From 4450fa1c83024aa28b34dc95326a61159d97b5dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=B2=D0=B0=D0=BD=20=D0=93=D1=80=D0=B0=D1=87=D1=91?= =?UTF-8?q?=D0=B2?= Date: Tue, 21 Sep 2021 21:59:33 +0500 Subject: [PATCH] Fixed crashing when not passing negative key --- koptilnya/input_system/cl_input.txt | 25 ++++++++++++++++------- koptilnya/input_system/configs/sample.txt | 13 ++++++++++++ koptilnya/input_system/main.txt | 10 ++------- 3 files changed, 33 insertions(+), 15 deletions(-) create mode 100644 koptilnya/input_system/configs/sample.txt diff --git a/koptilnya/input_system/cl_input.txt b/koptilnya/input_system/cl_input.txt index 3d48cd0..b17114c 100644 --- a/koptilnya/input_system/cl_input.txt +++ b/koptilnya/input_system/cl_input.txt @@ -27,7 +27,13 @@ function Input:noKeysHolding(axle) end 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 function Input:_trySetTargetValue(key) @@ -52,13 +58,18 @@ end function Input:_mapKeys(axles) for k, v in pairs(axles) do - self.keys[v.Negative] = { - Axle = k - } + if v.Negative ~= nil then + self.keys[v.Negative] = { + Axle = k + } + end + + if v.Positive ~= nil then + self.keys[v.Positive] = { + Axle = k + } + end - self.keys[v.Positive] = { - Axle = k - } end end diff --git a/koptilnya/input_system/configs/sample.txt b/koptilnya/input_system/configs/sample.txt new file mode 100644 index 0000000..f2301fa --- /dev/null +++ b/koptilnya/input_system/configs/sample.txt @@ -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 + } +} diff --git a/koptilnya/input_system/main.txt b/koptilnya/input_system/main.txt index 6bd7350..8f7db81 100644 --- a/koptilnya/input_system/main.txt +++ b/koptilnya/input_system/main.txt @@ -3,14 +3,8 @@ -- @shared -- @include ./cl_input.txt -- @include ./sv_input.txt -local Axles = { - Horizontal = { - Negative = KEY.D, - Positive = KEY.A, - Gravity = 0.1, - Sensitivity = 0.2 - } -} +-- @include ./configs/sample.txt +require('./configs/sample.txt') local options = { Axles = Axles