So, I’ve been working on a minigame currently. I’ve been working on details(the maps, effects, etc) but the main framework of the game is still a mystery to me. I’m trying to create a minigame system, where it just moves from one minigame, goes to the lobby, and goes to another random minigame. I was thinking of creating a
while true do end
But, it seemed like it would be a rather less efficient way , and not as useful as I would hope for it to be.
I’m trying to create a more organized framework, and I’m just trying to figure out what would be the best start for it.
You could use some sort of function that sets up and plays the round as well as an intermission sort of function/iteration.
An example would be like this:
while true do
local intermissionLength = 10
for i = 1, intermissionLength do
message.Value = "Intermission . . . " .. i -- Message being a stringvalue that causes a change in a player's gui text
wait(1)
end
pickMinigame()
startRound()
end
Each minigame should have a unique ID. Randomize (1, NumOfMinigames). Send event to server to start the minigame. Have a boolean for each player if in minigame/an int val of which minigame the player’s in. There should not be a loop for this.
So I could put all of the ID’s as Keys and the Maps as values or the other way around? sort of like this:
local currentGame = nil
local gameState = "Done"
local Maps = game.ServerStorage.Maps:GetChildren()
gameTable = {
["Touch the Block"] = 1
["Sword Fight"] = 2
["Go through the course!"] = 3
if gameState == "Done" then
currentGame = math.random(1, #gameTable)
gameState =="Play" -- I'm a little confused what I would do here.
for i,v in ipairs(gameTable) do
if v == currentGame then
for i,v in pairs(Maps) do
if v.Name = gameTable[i] then
v.Parent = workspace
end
end
end
}
I could change this up, but this is as close as I can guess it would look like.
The concept of the gameState seems very useful, as I can create a value that indicates the current gameState, and it will tell the server whether the game should start or not.
Ok the code above is a little inaccurate. What I think I can do is create a module which has every mini game function inside of it, and in a server script I can decide the intermission, and what mini game I could pick.
I figured out if I simply set up a dictionary for the minigame functions, then it would work(again, I’m not entirely sure if this works 100%, so I’ll gradually work my way around it.)
function module.StartRound() -- put this inside of a module script by the way
local Maps = game.ServerStorage.Maps:GetChildren -- the Maps are folders kept in another folder named Maps
local currentMap = Maps[math.random(1, #Maps)] -- Selects random map
local MinigameTable = {
["Touch The Blocks"] = function()
print("Hi") -- I can do whatever I want here for the match.
end;
["Fight with Swords"] = function()
print("Hello")
end;
["Jump Over the Lava Brick"] = function()
print("Greetings")
end
}
for i,v in pairs(MinigameTable) do
if i == currentMap.Name then -- what this means is if the stringValue is equal to the Map's folder name then it will use the function inside of the MinigameTable.
v() -- Just calls the function that it was assigned to.
end
end
end
Ok I figured it out. So I do need a while loop in another script, it would be very beneficial to have one in fact. These are the kind of situations that while loops are needed, which is why I’ll be using them in a seperate framework script. Since I figured this out, I’ll be making a guide later on once it’s polished and up and running.
Yeah that would work, it’s just the same way I did it, but the other way around. I’m not entireley sure if it would be MORe efficient though. Thanks for the suggestion!