I am trying to learn more about making my own commands, however I’m concern what can be better if I should use msg:lower() or if msg == using the plr.Chatted:Connect(function(msg)
argument.
- msg:lower()
- if msg ==
- Other (explain in replies)
0 voters
I am trying to learn more about making my own commands, however I’m concern what can be better if I should use msg:lower() or if msg == using the plr.Chatted:Connect(function(msg)
argument.
0 voters
Using (message == )
is very very inefficient, especially when it comes to setting up command flags etc, it’s best you use string.lower to compare commands to avoid getting any complications.
It’s always better to use msg:lower(), it’s basically a way to convert text that the computer can understand easily.
msg:lower() takes jumbled capitals such as I LoVe rOblOx and converts them to all lowercase; I love roblox. This removes the need to add extra arguments for potential capitalization uses inside messages.
You have to use both. string.lower()
just converts to lowercase, it doesn’t actually compare anything. Lowercase it to standardize capitalization and then compare.
No? This is just flat out untrue. It won’t be as effective, sure, but it’s undeniably faster.
Now if are going to get a tad bit more advanced, I recommend you start getting into String Manipulation and String Patterns, they might seem hefty at first, but when you get to understand them they’ll save your life with this stuff.
For example, this is a very quick parser I wrote using string patterns:
local function ParseMessage(Message)
local Args = {}
for argument in string.gmatch(Message, "%S%w+") do
table.insert(Args, argument)
end
print(Args[1]) -- would print the command name
print(Args[2]) -- would print anything after the command name
end
I mean if you believe so, then you can go ahead and not parse your messages at all and use a simple equality condition to determine what command a player invoked. When it comes to doing chat commands I believe and know it is a lot more than using equality statements, especially when it comes to having multiple command specifiers etc. I’m not stopping you from doing it, of course at the end of the day it’s my choice, but it’s just some advice.
I’m just saying efficiency has to do with speed, which is why I said “lowercasing is more effective” instead. It is factually false to say simply comparing two strings is slower than lowercasing one and then comparing.
Efficiency defines the accomplishment of achieving something while having the most competency in performance. Using equality statements instead of actually parsing your messages is very inproficient and doesn’t help in this situation at all.
That doesn’t make sense still.
a == b
is objectively “more efficient” than a:lower() == b
or whatever function you suggested Why? :lower()
is indexing the string, but strings can’t naturally be indexed. Strings have a metatable whose __index
field points back to the string
global. So then it has to index that versus just comparing them. Lowercasing the string is done so that case sensitivty does not matter since in your code you would be testing against a lowercase version of the message. You could even uppercase it if you wanted to, but then the strings would be screaming at you.
If we are going to be pedantic here then your function
string
global and indexes it with gmatch
, string.gmatch
evaluates to a function so that is called, so the function is called. The string pattern also needs to be parsed by the function to return everything that is a space followed by one or more occurrences of alphanumeric charactersprint
), index the tablestring.split
to split the message via a space?There was no point in you writing this ;p you simply recited everything I have written here so I don’t even understand why you bothered to write that out. Anyways, in the context of the post, the appropriate and more sensible answer would be to use string.lower() to compare chat commands, I don’t understand why you would do a == b
, especially when you have to be versatile while making chat commands.
I don’t think that was the point ? The point was simply, a == b
is objectively more efficient from a computational perspective, since you said
and further down in the context you implied your function was more efficient.
But as mentioned it is legit not worth discussing, it seemed like there was a lot of misinterpretation, also you never explained in depth how your function was less efficient in comparison to a relational operator.
If you’d like to continue discussion feel free to message me privately