How to store and get data

Post Reply
LC Creations
Member
Posts: 150
Joined: Mon Feb 18, 2019 02:53

How to store and get data

by LC Creations » Post

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.

Eran
Member
Posts: 123
Joined: Fri May 03, 2019 16:46

Re: How to store and get data

by Eran » Post

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]

LC Creations
Member
Posts: 150
Joined: Mon Feb 18, 2019 02:53

Re: How to store and get data

by LC Creations » Post

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)
Last edited by LC Creations on Tue Mar 31, 2020 08:53, edited 2 times in total.

User avatar
rubenwardy
Moderator
Posts: 6293
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy
Location: United Kingdom
Contact:

Re: How to store and get data

by rubenwardy » Post


LC Creations
Member
Posts: 150
Joined: Mon Feb 18, 2019 02:53

Re: How to store and get data

by LC Creations » Post

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)"

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], v-rob and 1 guest