1 Make getStorageValue returns other defaultValue, if specified.
All scripts with counters (kill tasks etc.) use something like that:
local storage = player:getStorageValue(123)
if storage == -1 then
storage = 0
end
or:
local storage = math.max(0, player:getStorageValue(123))
to make default value 0, not -1.
After changes it would be:
local storage = player:getStorageValue(123, 0)
2 Make setStorageValue saves -1 in database, if forceSave = true specified.
player:setStorageValue(123, -1, true)
would write value -1 to storages map and make it save in database.
These changes are backward compatible. Setting value to -1 with forceSave = false (default) would still remove storage from database.
We may consider removing forceSave parameter and make it always save -1 to database.
Only drawback would be that old scripts would not remove storages from database. In case someone got script, that uses 1000 storages for temporary data and remove them onLogout, it would increase player save time.
Someone complained about magic
-1
value in storages: https://otland.net/threads/whats-the-reason-you-cant-set-storage-to-1.279950/It looks like we still use storage system made 15 years ago.
Explanation of what you want to do that is currently impossible
Manage storages stored in database from Lua. Make storage with value
-1
settable.Current functions:
Desired functionality
Proposed functions (like in key-value databases: get/set/has/delete):
1 Make
getStorageValue
returns otherdefaultValue
, if specified.All scripts with counters (kill tasks etc.) use something like that:
or:
to make default value 0, not -1. After changes it would be:
2 Make
setStorageValue
saves-1
in database, ifforceSave = true
specified.would write value
-1
to storages map and make it save in database.These changes are backward compatible. Setting value to
-1
withforceSave = false
(default) would still remove storage from database. We may consider removingforceSave
parameter and make it always save-1
to database. Only drawback would be that old scripts would not remove storages from database. In case someone got script, that uses 1000 storages for temporary data and remove themonLogout
, it would increase player save time.