Hey, I’ve been trying to get into a little object oriented programming, but i’ve been having some trouble doing so. Currently, im attempting to obtain a table from a module script by using a variable with its name, but I can’t seem to do so.
My current attempts at setting a variable to its name, finding the table using table.find(), before taking the contents within has been a failure, returning only nils. Does anybody know how to do this?
Many thanks!
ModuleScript with room data
local roomInfo = {
-- table to get
["WideRooms"] = { -- I am attempting to obtain this table
["wideToNormal"] = {
["Weight"] = 1,
["Exit"] = "normal"
},
["wide"] = {
["Weight"] = 1
},
},
-- table to get
["NormalRooms"] = {
["StartRoom"] = {
["Weight"] = 0
},
["normal"] = {
["Weight"] = 1
},
["NormalToWide"] = {
["Weight"] = 1,
["Exit"] = "Wide"
},
["secret"] = {
["Weight"] = 0.01
},
}
}
return roomInfo
local room = {}
room.info = require(script.Roominfo)
room.lastExit = "WideRooms"
function room.GetRandom(prevRoom)
local totalWeight = 0
local spawnTable
local spawnTable = table.find(room.info, room.lastExit) -- trying to obtain the "WideRooms" table from earlier
for i, info in pairs(spawnTable) do -- invalid argument #1 to 'pairs' (table expected, got nil)
totalWeight += info.Weight
end