I’ve been working on creating a trivia game in Roblox, and I’ve made significant progress so far To the point I can start playtesting.
As of right now, I only have 20 questions hard-coded in. But now I need to start adding in way more questions. Right now, I have a JSON file with about 250+ questions (with plans to add even more), and in my JSON, I have it stored somewhat like this.
{"id":58,"text":"What do you call the 8 fl. oz. cup size thats just below a Tall at Starbucks?","choices":[{"correct":true,"text":"Short"},{"text":"Single"},{"text":"Small"},{"text":"Shy"}]},{"id":59,"text":"What two-word phrase was sent as the first cellular text message in 1992?","choices":[{"text":"Message sent"},{"correct":true,"text":"Merry Christmas"},{"text":"Love you"},{"text":"You up?"}]},{"id":60,"text":"What is NOT a disaster that can tear up your city in the first edition of SimCity ?","choices":[{"text":"UFO attack"},{"text":"nuclear meltdown"},{"text":"airplane crash"},{"correct":true,"text":"building collapse"}]}
But I’m now at a point where I’m trying to find the best approach for importing and managing these questions within my game. I would love some suggestions on how I can effectively store and manage my trivia questions for my game.
use modulescripts, they are good for storing massive data
in your case this is what you are seeking:
local http = game:GetService("HttpService")
local load = [[{"id":58,"text":"What do you call the 8 fl. oz. cup size thats just below a Tall at Starbucks?","choices":[{"correct":true,"text":"Short"},{"text":"Single"},{"text":"Small"},{"text":"Shy"}]},{"id":59,"text":"What two-word phrase was sent as the first cellular text message in 1992?","choices":[{"text":"Message sent"},{"correct":true,"text":"Merry Christmas"},{"text":"Love you"},{"text":"You up?"}]},{"id":60,"text":"What is NOT a disaster that can tear up your city in the first edition of SimCity ?","choices":[{"text":"UFO attack"},{"text":"nuclear meltdown"},{"text":"airplane crash"},{"correct":true,"text":"building collapse"}]}]]
return http:JSONDecode(load)
http:JSONDecode reads the JSON dictionary and turns it into a lua table, and returning it for scripts to use. to access, use require(the.module.script)
Your way seems to be good enough. You could edit some thing tough, like adding a little more detail and order. Let me show what I mean with a simple table.
local Questions = {
["Two_Players"] = {
["Topic_1"] = {
["Question_1"] = {
["Question"] = "",
["Choices"] = {"Option_a","Option_b"}, -- example
["Points"] = 10, -- example
["Answer"] = "Option_a",
},
},
["Topic_Burgers"] = {...},
},
["Three_Players"] = {
.....
}
}
-- You can eventually encode (Convert) this to a JSON and reverse
Yep this seams to work the best, I was planning on using a self ran website hocked up to MongoDB, But when I got down to thinking about I would still need to store some question in the game as a back up if the website every died