Gone, Sorry, ------------------------
What if I want to assign multiple functions to my W key? I havenāt checked the code, it may use newindex to connect the function behind the scenes. However, it isnāt implicit from the design and isnāt explained within this thread, so can I do so?
Donāt work with inputs too much, but I remember how painful and unintuitive they were to use. The approach you are taking now, for the most part, seems to be right up my alley if I ever get to work on UI again.
No, you cannot.
Thank you for pointing this out, I will implent this, 15 ish minutes prolly.
This is what AI has said about this,
-- Assign the first function to the 'W' key press event
CoolerInput.Began[Enum.KeyCode.W] = function1
-- At this point, when 'W' is pressed, 'function1' will be called.
-- Now, assign a second function to the *same* 'W' key press event
CoolerInput.Began[Enum.KeyCode.W] = function2
-- Because of how the 'CoolerInput.Began' table and its __newindex work,
-- this assignment (CoolerInput.Began[Enum.KeyCode.W] = function2)
-- *overwrites* the previous value stored for Enum.KeyCode.W in the
-- internal 'beganCallbacks' table.
-- So, 'function1' is replaced by 'function2'.
-- When the 'W' key is actually pressed by the user, the InputBegan
-- event handler in the CoolerInput module looks up the callback
-- for Enum.KeyCode.W. It finds and calls only the *single* function
-- currently stored there, which is 'function2'.
-- Therefore, 'function1' will NOT be called, only 'function2'.
Updated! Tbh I just used ai to make it based off of how I told it to do, you can now run multiple functions at once with,
CoolerInput.Began[Enum.KeyCode.W] = function1
CoolerInput.Began[Enum.KeyCode.W] = function2
Your comment also gave me the idea to do something like this though | which I am now working on
function print1()
print("1")
end
function print2()
print("2")
end
CoolerInput.Began[Enum.KeyCode.E] = {print1(), print2()}
thank you for your comment. ![]()
![]()
Why is listening to input events done via __index and __newindex instead of via simple static functions like CoolerInput.combinationEnded(), CoolerInput.began(), etc? Not only is this slower, itās also way uglier and way less readable, which is what your title claims to fix ![]()
> Also, typo!:
![]()
I quite like the idea of multiple being accepted at once!
I have a few assumptions that may need to be cleared up.
- The function input into
RegisterSequencewill run whenever the keys are pressed in a specific order, and can run multiple times. - For timed RegisterSequences, the timer will only start when pressing the first key and will immediately stop when another key other than the second is pressed.
I have a few more ideas.
-
Ability to exclude keys from registerSequences, mainly so we can move whilst performing the sequence.
-
Ability to register a sequence that runs only once.
-
Ability to register a sequence that has a cooldown period.
I never Stated that this is a faster approach,
Being honest here, I am not a great programmer, I donāt know hwat static functions are,
. I will look into this though, especailly since its a faster and better approach.
And for code readability, I donāt frankly care about what people consider looks better, only what looks good to ME, if others really care about readability they can edit it themselves, since this module is just a helping module and many prolly wont edit it.
Iām not talking about the readability of the module, Iām talking about the readability of code using this module
Using __index and __newindex to register callbacks not only is confusing for even decently large codebases, itās also just bad practice in general (luau extremely discourages using __newindex as a function in the first place, not to mention using it for stuff like this)
Static functions are just functions that donāt change and arenāt methods (aka are called with . instead of :), for functions which just do some specific thing unrelated to objects, they are recommended to be static, both for performance and usability (you can declare static functions as its own variable without needing to pass self as the first parameter)
Fair enough, I know a good few people who writes code like this
Though C++ overloads << for stream writing, doesnāt mean itās not bad practice.
Though, if youāre gonna make whatās readable only to you, Iād change the title. It generally declares that this module is gonna solve all your ugly input code problems ![]()
The function input into
RegisterSequencewill run whenever the keys are pressed in a specific order, and can run multiple times.
ā Can fix that,
For timed RegisterSequences, the timer will only start when pressing the first key and will immediately stop when another key other than the second is pressed.
ā Can fix that,
I like your ideas alot. Definitely alot on my plate to handle though, it is worth it to make the module as best as it can be for sure.
these fixes/ideas will take around and hour or 3,
useless bloat resource, created with AI, not point in using it and the syntax is not nice to look at
For this, I feel like if the types matched the intention is would be alright. Although I do agree that it requires a few extra glances and some time to consult the ancient one in order to understand what exactly is going on.
Oh.. didnāt even know it could be a table. Thanks for that tidbit, although it means I will have to do alot more work.
For @SimplyBamb000: Encountered the same issue myself not too long ago, my solution was to do:
-- Was
local a = {}
a.b = function() end
-- Now
local a = {} :: {b: (func: (whateverArgs: any)->()) -> ()}
-- Has function autocomplete***
a.b(function(whateverArgs) end)
Oh gosh, you misunderstood. I did not say there was an issue with them, only that I was uncertain the exact meaning behind them and wanted confirmation as to whether my assumptions were correct.
Itās not useless. Though I admit it has some bloat. Itās not AI-generated, except for a small part/quick fix version (1.1), where I used AI to help structure how multiple functions could be handled through a single input. However, I gave it good clear instructions, and the final code worked without issues.
Iām not an expert programmer, but hearing someone label my work as āAI-generatedā is annoying, especially when Iāve put real effort into creating something Iām open to improving.
Sorry if the code looks like it came from AI, but that is not the case.
Edit : The post is ai, only reason why is I am not an english speaker/writer, and I also wanted some more comical feelings out of it, as a joke saying āHey, robloxs userinputservice is hard to readā
Sorry, english is not my native language, I google translate. Your assumptions are probably correct, you can always test urself.
I feel like this is kinda solving a nonexistent problem when it comes to just detecting basic inputs, you can either use CAS, or even with UserInputService itās either a few if statements, or you make a table describing all the inputs you wanna detect and 1 InputBegan connection which simply accesses an entry from it using the InputObject, in which case you know exactly what is going on at all times, and can easily make simple functions that just add an input and a callback to one of the tables
For combinations and sequences tho I do agree a free utility module is nice to have, though the way it is implemented is very hard to modify or even understand
It would be nice if you maybe stepped back and rethinked how the entire thing works, and how you could make it more straightforward to understand (Not only is this beneficial for people who wanna edit the module itself, itās also beneficial for people who just use it, who now know exactly how it works and will know what bugs/issues in their game are perhaps caused by some usage of the module, and even yourself, who now is able to maintain the module better and more efficiently)
Again, I get your point and side. I will say 1 thing, this is a resource for many people to use that are donāt enjoy how robloxs UIS is used. Or for people that are too lazy or want atleast SOMETHING to refrence to if they wanted to make it, yet it may not be the best readable code, it is atleast something.
Iām just saying, if youāre gonna post resources on the devforum you should try improving them, for yourself and others too, instead of just saying āit is what it isā :V
I get where youāre coming from improving resources is always the goal, and feedback is key for that. My point was just that posting something with the intent to refine it (and being open to suggestions) is better than treating it as āfinalā when it could be better.
I am not aurging about this, but I apprecitate you for telling me about static functions.
Sorry bro this aint it. regular connect is way superior and this just lacks functionality
Shift+C ā nothing
C+Shift ā Left Shift + C Began