Hello all,
One of the experiences I help develop relies on a considerably large number of clickable elements in tight spaces. I’ve been asked to do a complete rebuild of our old control manager lately, and I’ve been exploring ideal ways to do this.
So far, I’ve decided to create a dictionary of controls, values, and functions to make it convenient to find and add new controls to the list as needed. They’re in a module-script as well, so that they can be triggered from non-player inputs also.
Edit: The purpose of doing things this way is so that we can easily keep a track of which buttons are pressed, in what order, etc.
Example:
["Alpha-A"] = {
["type"] = CtrlTypes.Button,
["obj"] = Switches:FindFirstChild("SwitchA"),
["state"] = false,
["fn"] = {
["lmb"] = function()
-- change state to true
end
}
},
… and many other such listed controls here. We have a loop that goes through this table at runtime to locate where the ClickDetectors are and then call back to these [“fn”][“rmb”]/[“lmb”] functions later on, and it works a charm; but that’s unrelated.
The first question is whether or not this is a good way of keeping track of things! I am in uncharted territory writing this new system in hopes that what results will be easy to use for both me and our other developers. I would really appreciate some insight on what should or should not be done.
The second question is, how can I change the parent key value ‘state’ from within the function below? I’m fairly certain that you can’t reference values to a table, within that table, as it needs to be instantiated first; but I would like to be sure, and get recommendations if possible.
Insight and thoughts are very much appreciated. Thanks for any reply.
– Cyton