ApeRuss
(ApeRuss)
March 23, 2022, 8:23pm
1
So I’m working on my own admin commands, but I stumbled upon a problem
so basically if the string is trying to find “health” it finds my other command “heal”, I tried to look for some solutions but couldn’t be backed by 1, any help here would be appreciated, thanks
ApeRuss
(ApeRuss)
March 23, 2022, 8:35pm
3
If I consider health the first elseif then it the other command wouldn’t function because it would just get the first command
If the goal is an exact match you don’t really need match
, you can just compare “textstringye” to the concatenated prefix and string. I would also use the string’s library’s lower
function so that it doesn’t matter how things are capitalized.
1 Like
ApeRuss
(ApeRuss)
March 23, 2022, 8:37pm
5
There is more characters to the string, basically “:health me 50”, I already tried using string.sub but that still didn’t work for me for some reason
And using string.find just gives me the same issue
Here is some pseudo-code where you write health under the first match:
if match(heal) then
if match(health) then
> run health command
else
> run heal command
end
end
You can also just run multiple checks against the string to check which one is correct using and
.
1 Like
ApeRuss
(ApeRuss)
March 23, 2022, 8:41pm
7
Even tho it’s a minor issue, my brain couldn’t think of that for some reason
appreciate you
Forummer
(Forummer)
March 23, 2022, 9:57pm
8
You could also just switch the order of the elseif conditional checks.
heal
is contained within health
but not vice versa.
2 Likes
ApeRuss
(ApeRuss)
March 23, 2022, 10:39pm
9
As I said, that would still make the same issue, the other elseif under it wouldn’t work, I already figured it out so ye
Forummer
(Forummer)
March 23, 2022, 11:49pm
10
No it wouldn’t, take the following for example.
local word = "healths"
if word:match("heal") then
print("1")
elseif word:match("health") then
print("2")
end
local word = "healths"
if word:match("health") then
print("1")
elseif word:match("heal") then
print("2")
end
In both cases 1 is printed.
1 Like