From 4524aee758d16b36849f57e6b45e849dae33d25d Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Mon, 15 Jun 2020 23:32:32 +0200 Subject: [PATCH] Fix controls mod crashing in 5.3.0-dev --- mods/CORE/controls/init.lua | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/mods/CORE/controls/init.lua b/mods/CORE/controls/init.lua index d2820eef0d..a219b794c6 100644 --- a/mods/CORE/controls/init.lua +++ b/mods/CORE/controls/init.lua @@ -16,19 +16,24 @@ function controls.register_on_hold(func) controls.registered_on_hold[#controls.registered_on_hold+1]=func end +local known_controls = { + jump=true, + right=true, + left=true, + LMB=true, + RMB=true, + sneak=true, + aux1=true, + down=true, + up=true, +} + minetest.register_on_joinplayer(function(player) local name = player:get_player_name() - controls.players[name] = { - jump={false}, - right={false}, - left={false}, - LMB={false}, - RMB={false}, - sneak={false}, - aux1={false}, - down={false}, - up={false} - } + controls.players[name] = {} + for cname,_ in pairs(known_controls) do + controls.players[name][cname] = { false } + end end) minetest.register_on_leaveplayer(function(player) @@ -40,7 +45,9 @@ minetest.register_globalstep(function(dtime) for _, player in pairs(minetest.get_connected_players()) do local player_name = player:get_player_name() local player_controls = player:get_player_control() + if controls.players[player_name] then for cname, cbool in pairs(player_controls) do + if known_controls[cname] == true then --Press a key if cbool==true and controls.players[player_name][cname][1]==false then for _, func in pairs(controls.registered_on_press) do @@ -59,5 +66,7 @@ minetest.register_globalstep(function(dtime) controls.players[player_name][cname] = {false} end end + end + end end end)