I am trying to make a system where commands could be decoded in a parser. While creating the system I came across an issue. After getting help with splitting a command that contained multiple players. After resolving that issue I came across another conflict with separating the players and the value/message.
Since not all players will type the command perfectly every single time it’s fired, I am trying to make typing the commands as simple as possible. If I wanted to parse the message
kick Player1,Player2,Player3 Kicked from the game, don't join back.
When you split the message with the partial system I have now, it splits the message and removes the comma.
msg = "kick Player1,Player2,Player3 Kicked from the game, don't join back"
local SplitMessage = string.split(msg, ",")
local Command = string.match(SplitMessage[1], "[%w]+")
local Players = {string.sub(SplitMessage[1], #Command + 2, #SplitMessage[1])}
if #SplitMessage > 1 then
for i,v in ipairs(SplitMessage) do
if i ~= 1 then
local split = string.find(v, " ")
if split then
mes = string.sub(v, split)
print (mes)
end
if v == game.Players:GetPlayers().Name then
local SubbedPlayer = string.gsub(v, "%s?", "")
table.insert(Players, SubbedPlayer)
else
local m = string.find(msg, v)
local message = string.sub(msg, m)
end
end
end
end
Output:
Are the anyways to cancel the split after the final player argument in the command? If not, are there any ways I could make this work?
Hmm my bad I misread the code. It looks like it’s just because you’re splitting by a comma. Each half is being printed separately. Are you asking for how to solve that issue? If so I’d recommend selecting a point in the split message to rejoin everything. You can then use table.concat with a comma to merge everything.
My problem with concatenating is when everything is split, the comma gets removed and is no longer in the message. I was wanting to stop the split after the final player, but if concatenating is the only solution then I’ll try that.
Concatenate wouldn’t work 100% of the time. The way the message is found is if there is a space in between a split message. i.e, if the final player had a part of the message it would split that part of the argument into the message. But, after that how would I define the rest of the message? Using “i” in the for loop?