From 4b0d92625ec2a631463157c5625a8ad709d6e797 Mon Sep 17 00:00:00 2001 From: Chr1Z93 Date: Thu, 24 Oct 2024 13:51:50 +0200 Subject: [PATCH 1/2] Changed save function for better performance --- src/core/GenericCounter.ttslua | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/core/GenericCounter.ttslua b/src/core/GenericCounter.ttslua index baabb4c4..943f619f 100644 --- a/src/core/GenericCounter.ttslua +++ b/src/core/GenericCounter.ttslua @@ -1,11 +1,13 @@ local MIN_VALUE, MAX_VALUE = 0, 99 val = 0 -function onSave() return JSON.encode(val) end +function updateSave() + self.script_state = val +end function onLoad(savedData) if savedData and savedData ~= "" then - val = JSON.decode(savedData) + val = tonumber(savedData) or 0 end self.max_typed_number = MAX_VALUE @@ -51,6 +53,7 @@ function updateVal(newVal) if tonumber(newVal) then val = math.min(math.max(newVal, MIN_VALUE), MAX_VALUE) self.editButton({ index = 0, label = tostring(val) }) + updateSave() end end @@ -61,6 +64,7 @@ end function modifyValue(mod) val = math.min(math.max(val + tonumber(mod), MIN_VALUE), MAX_VALUE) self.editButton({ index = 0, label = tostring(val) }) + updateSave() end function onNumberTyped(_, number) From 3d3535cef7d89578b6b3cea85314f87e2b66fed8 Mon Sep 17 00:00:00 2001 From: Chr1Z93 Date: Thu, 24 Oct 2024 13:54:55 +0200 Subject: [PATCH 2/2] added "onDestroy()" handling --- src/core/GenericCounter.ttslua | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/core/GenericCounter.ttslua b/src/core/GenericCounter.ttslua index 943f619f..3e2b13f5 100644 --- a/src/core/GenericCounter.ttslua +++ b/src/core/GenericCounter.ttslua @@ -1,15 +1,15 @@ local MIN_VALUE, MAX_VALUE = 0, 99 -val = 0 + +function onDestroy() + updateSave() +end function updateSave() self.script_state = val end function onLoad(savedData) - if savedData and savedData ~= "" then - val = tonumber(savedData) or 0 - end - + val = tonumber(savedData) or 0 self.max_typed_number = MAX_VALUE local tokenType = self.getMemo()