Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

What is the best way to organize "match" system?

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

1 answer

You could have maps be a dictionary of game modes = maps, sort of the reverse of what you currently have. Cus you probably want something to easily index. Also try to store the actual selected values, not the index.

--my prototype--

local gamemodes = {"FFA", "TDM"} --example modes

local maps =
{
	FFA = {"BASEPLATE","N00BLANDS"},
	TDM = {"YOUR_LAWN","N00BLANDS"}
}
--^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 = gamemodes[math.random(#gamemodes)]
    print("GAMEMODE "..mode.. " HAS BEEN CHOSEN!")
    wait(2)
    print("PICKING MAP!")
    wait(2)

    local mapsT = maps[mode]
	local map = mapsT[math.random(#mapsT)]

    print("MAP ".. map .. " HAS BEEN CHOSEN!")
    wait(2)
    print("LOADING DATA...")
end

match() --test calling the match function

5 comments

0

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.

0

oh and there is actually still no real links between the maps directory and gamemodes table but I'll see

0

I don't get what you mean by "real link between".

0

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

0

There would be no point to linking them.

This discussion is preserved as it was. New answers, comments, and votes are closed.