diff --git a/src/core/GenericCounter.ttslua b/src/core/GenericCounter.ttslua index baabb4c4..3e2b13f5 100644 --- a/src/core/GenericCounter.ttslua +++ b/src/core/GenericCounter.ttslua @@ -1,13 +1,15 @@ local MIN_VALUE, MAX_VALUE = 0, 99 -val = 0 -function onSave() return JSON.encode(val) end +function onDestroy() + updateSave() +end + +function updateSave() + self.script_state = val +end function onLoad(savedData) - if savedData and savedData ~= "" then - val = JSON.decode(savedData) - end - + val = tonumber(savedData) or 0 self.max_typed_number = MAX_VALUE local tokenType = self.getMemo() @@ -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)