What would the most performant way of having a toggleable debug mode be in a module script

Basically, I am making a bunch of modules scripts that are connected and what it to be easy to debug them, but I also don’t want the debugging code in the main game since it could affect performance.

I was wondering if it would be more efficient to have a bunch of if statements or if it would be better if I just created two different modules that I could switch between based off of a boolean (one module would be good for debugging).

1 Like

Why don’t you just include a function for debugging and just check if the script is being run in a studio environment?

local isStudio = game:GetService("RunService"):IsStudio() -- returns bool

local function debug_func() -- func for debugging stuff
    ...
end

if isStudio then -- run if it IS in a studio environment
    debug_func()
end

or if it’s supposed to be in a module for external calls;

-- In the modulescript

local module = {}

function module.debug_func() -- function for debugging
    ...
end

return module;
-- In your other script wherever

local module = require(path_to_module) -- get the ModuleScript

local isStudio = game:GetService("RunService"):IsStudio() -- Returns bool
if isStudio then -- run debugging if it's in studio
    module.debug_func()
end

I’m not super clear on what you’re asking, but I hope this helps.

Basically, if I made two modules, they would look like this:

local module = {}

function module.test1(argument){
      if type(argument) ~= "string" then
            return
      end
      print(argument)
end

return module

and this:

local module = {}

function module.test1(argument){
      print(argument)
end

return module

Basically what I mean by “debugging” is just verifying arguments and outputting errors in a more readable format.

I’m basically just asking if it would be more efficient to just have one big if statement wrapping the debugging sections or would it be more performant to make another module specifically for debugging (keep in mind this would probably be disabled or deleted in the main game).

I’m just unsure of if all the if statements running or if an extra module in the game would have a greater impact on performance.

Sorry if this was unclear before

1 Like

Regardless, this is typically best practice. Overall, it likely won’t have much of an impact at all to simply output errors with some sort of readability, and ABSOLUTELY verify arguments, especially if being run in the main game. That is baseline for basically any script.

Just include the error handling and arg verification inside of where it’s needed.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.