Query On Saving And Loading Data To Files

Eorzea Time
 
 
 
言語: JP EN FR DE
日本語版のFFXIVPRO利用したい場合は、上記の"JP"を設定して、又はjp.ffxivpro.comを直接に利用してもいいです
users online
フォーラム » Windower » Support » Query on saving and loading data to files
Query on saving and loading data to files
Offline
Posts: 512
By Zubis 2021-08-26 20:26:59  
So this is stupid. I know it's stupid, but I've spent longer than I'd like to admit on this and I'm hoping someone can spot the problem.

I have a very simple Add-On defined below, which simply creates a settings file and writes a timestamp to it every time the Add-On is loaded.

The first time it is loaded it runs fine. It adds the timestamp to the settings file.
Code
_addon.name = 'Test'
_addon.author = 'Zubis'
_addon.commands = {'Test'}
_addon.version = '0.0.0.0'

require('tables')
config = require('config')

local defaults = T{}
defaults.timestamps = T{}
settings = config.load(defaults)

local timestamp = 'Timestamp: ' .. tostring(os.time(os.date("!*t")))
if settings.timestamps:contains(timestamp) == false then
    settings.timestamps[#settings.timestamps+1] = timestamp
	settings:save('all')
end


"//lua r test" gives this output on Run #1:


"//lua r test" gives this error on Run #2:
attempted to compare string with number

Any ideas?
 Fenrir.Niflheim
VIP
Offline
サーバ: Fenrir
Game: FFXI
user: Tesahade
Posts: 435
By Fenrir.Niflheim 2021-08-26 23:21:39  
You cant use settings with numeric keys, they will be turned into strings when you load them, so "1" instead of 1.

Here is a pull request where it was discussed:
https://github.com/Windower/Lua/pull/1607

rather than `T{}` use a list or set.
[+]
Offline
Posts: 512
By Zubis 2021-08-27 04:14:48  
Ah got it, thanks so much for replying. It was driving me crazy.