Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
local player_inv = player:get_inventory()
local list = player_inv:get_list("main")
local retval = {}
for _, stack in pairs(list) do
retval[#retval + 1] = stack:to_string()
end
local data_base = minetest.serialize(retval)
Can an item in list be nil?
Even if not, l'd use the index from the list:
- Code: Select all
local player_inv = player:get_inventory()
local list = player_inv:get_list("main")
local retval = {}
for n, stack in pairs(list) do
retval[n] = stack:to_string()
end
local data_base = minetest.serialize(retval)
Are you sure that get_list returns a copy?
l guess else there wouldn't be the set_item and remove_item