Hi, I’m making a module that contains tips for certain places. Ignore the places and tips, it’s a meme game.
As I was assembling the main module I thought: "How I can choose a random place between all of them in the tips table, and assign it to a text button in the GUI that lets you select the place?"
Here’s what I have so far, it’s not complete yet but I’d like a bit of help to finish it
local tips = {
["Arizona"] = {
"Beware the sunstroke debuff. Try to alleviate it before your health reaches 0",
"Flipflops are inconvenient to wear here, they will hinder your movement",
"",
}
}
function tipDisplay(name, place)
local randomTip = tips[math.random(1, #tips[place])]
local randomPlace = tips[math.random(1, #place)]
end
return tips
For those curious, here's the GUI of the places selectable
local module = {}
module.tips = {
["Arizona"] = {
"Beware the sunstroke debuff. Try to alleviate it before your health reaches 0",
"Flipflops are inconvenient to wear here, they will hinder your movement"
}
}
local rand = Random.new()
-- e.g. module.GetRandomTipFrom("Arizona")
function module.GetRandomTipFrom(place: string)
local index = module.tips[place]
if index then
return index[rand:NextInteger(1, #index)]
end
end
return module
This is awesome.
I can just require the module from the textlabel and run the randomtip function there, right? Or how can I implement it cause I’m not very experienced with modules just yet
Bad attempt at code in the TextLabel
local tipsModule = require(game:GetService("ReplicatedStorage"):WaitForChild("TipsModule"))
tipsModule.GetRandomTipFrom()