I’m in the early stages of making a framework for my game, I’m trying to figure out ways I can get modules to be dedicated to specific aspects of the game, UI, the player, Sounds, Entities ect.
I’ve gone through and added the necessary code to make my own console, which will allow me to let players type in cheat codes, heres how it looks at the moment;
The modules are the only things in use here, the main script just connects.
Settings control what the inputs are tied to, the console service is currently very short, but will take the input given to it and decide what should be done.
I don’t know about you, but I’d say this is messy and non-clear code. It doesn’t feel organised.
Is there a better approach I could be taking to making sure that it is not only clear, but efficient?
Have a dedicated InputBegan in your Console module, which might ask Settings which KeyCode to listen for
Do like you do now
Same as you do now, but let Settings only tell you the key
Either Controls[Enum.KeyCode.Backquote] = "ConsoleToggle"
and in InputBegan see what Controls[input.KeyCode] means and do stuff based on that
Or have Controls.ConsoleToggle = Enum.KeyCode.Backquote
and loop through the Controls on InputBegan.
Allows for multiple functions to be bound to one keycode, but eh
Have your Console register itself to the Input module, something like Input:Register("ConsoleToggle",CONSOLE_SERVICE.Toggle) (more to be combined with the previous point for the Controls table) (could also change the name into the actual KeyCode, but then Console depends on Settings)
Your setup isn’t actually that bad. Just use something that you feel fine with and that is not too complicated. You can spend some extra time in the beginning on this, as it’s difficult to change later on, but don’t overdo it. I’ve overdone it plenty of times, and I still do
I used to try to make “frameworks” but then I just gave up when it legit took 10000000% longer to make anything I wanted because of how they were set up.