How could I improve my Dynamic FFlag System?

Hi,

So recently I’ve been working on making a DFFlag system for my game. Roblox’s own FFlag system has always intrigued me, so I wanted to make one for myself. I’ve already gotten the FFlag system down, and I think I might have gotten the DFFlag system working great, but I would like some feedback on it. More information on Flags can be here.

FFlag’s and DFFlags are great ways of testing updates, if something goes wrong I can flick off a flag without actually having to update my game. While the system works, I’ve noticed it can be a bit slow. GitHub hosting can take up to 5 minutes to update, which isn’t the problem. Even when I see the exact data that is being called from the GET request, it doesn’t always update until a couple tries. I’m guessing that’s due to some inefficiency in my code I’ve overlooked.

I’m using JSON to control the flags, it’s easiest for me because I can quickly change the flag via VSC and then commit and push to GitHub hosting in around 30 seconds.

Anyway, onto the code:

JSON Configuration (Flag Storage)


{
    "test1" : true,
    "level1open" : true,
    "allfflagsenabled" : true
}

Lua Code

local HttpService = game:GetService("HttpService")

local function request()
	local response = HttpService:RequestAsync(
		{
			Url = "https://raw.githubusercontent.com/FxllenCode/TheInternFFlags/main/fflags.json",
			Method = "GET",		
			Headers = {

				["Cache-Control"] = "no-cache"

			}
		}
	)


	if response.Success then
		print("Status code:", response.StatusCode, response.StatusMessage)
		local data = response.Body
		local parsed = HttpService:JSONDecode(data)
		if parsed.level1open == true then
			print("Level 1 is open.") -- other stuff too
		elseif	parsed.level1open == false then
			print("Level 1 is closed.") -- other stuff too
		end
	else
		print("The request failed:", response.StatusCode, response.StatusMessage)
	end
end

while true do

	local success, message = pcall(request)
	if not success then
		print("Http Request failed:", message)
	end

	wait(300)
end


Still looking for some feedback on this system. I’m considering making a tutorial on this so some review on how the code works would be great. :slightly_smiling_face:

it would be pretty difficult to give feedback off such a small chunk of code lol. Only things I could point out are some micro-optimizations. (Good Job :)))

1 Like

Any optimization is great! I’d love to hear your thoughts on how I could improve it.

Good Code, but a few nitpicks:

  • Table should be referenced instead of having to be packed each time the request subroutine is called.
    ex.
local httpArgument = { -- I'm sure you can give a more clear variable name :/
   {
      Url = "https://raw.githubusercontent.com/FxllenCode/TheInternFFlags/main/fflags.json",
      Method = "GET",
      Headers = {
         ["Cache-Control"] = "no-cache",
      }
   }
}
  • I didn’t see a need to define the data variable. Since there is already enough context that the :JSONDecode method accepts data to serialize.
local function request()
    local response = HttpService:RequestAsync(httpArgument)
    if response.Success then
        print("Status code:", response.StatusCode, response.StatusMessage)
        local parsed = HttpService:JSONDecode(response.Body)

        if parsed.level1open == true then
           return print("Level 1 is open.") -- other stuff too
        end
        return print("Level 1 is closed.")
    end
    return print("The request failed:", response.StatusCode, response.StatusMessage)
end

while true do
    local success, message = pcall(request)
    if not success then
        print("HTTP Request failed:", message)
    end
    wait(300)   
end

Like I said, most of my points won’t show any real optimizations to your code :joy: (Only optimization I would take more seriously is my point about table referencing instead of packing).

2 Likes