I'm doing a game with a few of my friends, and I have to rewrite the match system of the game. I could of course make it fast and have it just work if I want to, but I prefer quality over speed, and that's one of the reasons I am rewriting it. I figured out how to start it good now, but I don't think it's the best way to do it, I don't like having gamemodes and maps not linked:
--my prototype--
local gamemodes = {"FFA", "TDM"} --example modes
local maps =
{
{id = "BASEPLATE",mode = {"FFA"}}; --example names
{id = "YOUR_LAWN",mode = {"TDM"}};
{id = "N00BLANDS",mode = {"FFA","TDM"}};
}
--^only thing that links these two is the names and I don't find it very nice
function match() --the match function, the heart of the game
print("PICKING GAMEMODE...")
wait(2)
local mode = math.random(1,#gamemodes)
print("GAMEMODE "..gamemodes[mode].. " HAS BEEN CHOSEN!")
wait(2)
print("PICKING MAP!")
wait(2)
local browser = {}
for k,v in pairs(maps) do
if v.mode then
for _,m in pairs(v.mode) do
if m == gamemodes[mode] then
table.insert(browser,v.id and v.id)
end
end
end
end
local map = math.random(1,#browser)
print("MAP ".. browser[map].. " HAS BEEN CHOSEN!")
wait(2)
print("LOADING DATA...")
end
match() --test calling the match function
If you can help in anyway, I'd appreciate if you'd post an answer to this question.
Thanks,
SwaggyDuckie

5 comments
Good idea, thanks. I'll see if there's any better and if not you'll receive your accepted answer. I saved the key value for the tables 'cause I thought I might need it later in my way to do it. Thanks though.
oh and there is actually still no real links between the maps directory and gamemodes table but I'll see
I don't get what you mean by "real link between".
I mean the names of the gamemodes and the keys of the dictionary that use the same name are not linked in anyway but I will probably stick with the not linking since there doesn't seem to be any other way
There would be no point to linking them.