Page 1 of 1

How to store and get data

Posted: Tue Mar 31, 2020 07:07
by LC Creations
I'm creating a mod for online shopping. It adds to the currency mod that has shops. I know how I'm gonna do it but I need a place to store data. For example, I have a list of strings that I will set as a single string that is set by a single player then I want to get it in another function on another formspec accessed by all players. I also want the data or object to be saved when the client closes and when it opens it's still there. I cannot use mod storage becuase mod storage can only be accessed durring load time. I do not want to use player meta because then I have to search through every player to do what I want, and if you don't know why I do not want to use node meta then you probably also wont be able to answer this question.

I need a easy global place to store metadata just like player metadata that can be accessed anywhere, in any function, and can be saved like player metadata. The fact that this does not already exist is pretty infuriating.

Re: How to store and get data

Posted: Tue Mar 31, 2020 07:47
by Eran
Mod storage can NOT only be accessed during load time. You can only call minetest.get_mod_storage() during load time but the storage object it returns can be used whenever. So do something like this:

Code: Select all

local storage = minetest.get_mod_storage()
[rest of the program]

Re: How to store and get data

Posted: Tue Mar 31, 2020 08:22
by LC Creations
Eran wrote:Mod storage can NOT only be accessed during load time. You can only call minetest.get_mod_storage() during load time but the storage object it returns can be used whenever. So do something like this:

Code: Select all

local storage = minetest.get_mod_storage()
[rest of the program]
Wherever I use

Code: Select all

mod_storage:set_string("mykey", "myvalue")
It says "bad argument #1, (string expected, got table)

Re: How to store and get data

Posted: Tue Mar 31, 2020 08:37
by rubenwardy

Re: How to store and get data

Posted: Tue Mar 31, 2020 08:41
by LC Creations
rubenwardy wrote:Modding book chapter: https://rubenwardy.com/minetest_modding ... orage.html
Rubenwardy I just did everything that you just showed me but when I do

Code: Select all

set_foo("desiredkey", "desiredstring")
, I get an exception and it says "bad argument #1 (string expected, got table)"