From 042405cb63a7fa31ee30a6ac6ed607acecef64f3 Mon Sep 17 00:00:00 2001 From: NullBite Date: Fri, 18 Mar 2022 23:55:52 -0400 Subject: [PATCH] Avoid accessing state variables within pings The host instance of the variable should be authoritative to ensure host and clients are in sync --- script.lua | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/script.lua b/script.lua index 652ab5f..72b6c85 100644 --- a/script.lua +++ b/script.lua @@ -3,6 +3,8 @@ -- Texture dimensions -- TEXTURE_WIDTH = 128 TEXTURE_HEIGHT = 128 + +-- local state variables (do not access within pings) -- armor_enabled=true vanilla_enabled=true @@ -116,7 +118,7 @@ end action_wheel.SLOT_2.setTitle('log health') action_wheel.SLOT_2.setFunction(function() print(player.getHealth()) end) action_wheel.SLOT_3.setTitle('Toggle Armor') -action_wheel.SLOT_3.setFunction(function() ping.setArmor() end) +action_wheel.SLOT_3.setFunction(function() setArmor() end) -- Pings -- --- Damage function -- @@ -130,16 +132,19 @@ end function ping.healed(health) setExpression(0,0) end + --- Toggle Armor --- -function ping.setArmor(enabled) - if enabled == nil then +function setArmor(state) + if state == nil then armor_enabled=not armor_enabled else - armor_enabled=enabled + armor_enabled=state end - + ping.setArmor(state) +end +function ping.setArmor(state) for key, value in pairs(armor_model) do - value.setEnabled(armor_enabled) + value.setEnabled(state) end end -- }}}