Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How to search for a space in chat?

Asked by
stepatron 103
6 years ago
Edited 6 years ago

This is for an admin script. How do I have it search for the second space? So like ``;;setHealth [Player] [newHealth]" I cant figure out how to have the script 'know' what part is the name and what part is the value that the health will be set to

1 answer

Log in to vote
1
Answered by
Avigant 2374 Moderation Voter Community Moderator
6 years ago

String patterns are just what you need. I recommend splitting the string after the signal character(s) (in your case, the ";;") into a command and argument.

01local SignalCharacters = ";;"
02local Message = ";;setHealth Username 100"
03 
04function HandleMessage(Message)
05    if Message:sub(1, #SignalCharacters) ~= SignalCharacters then
06        -- Return early if message isn't a command
07        return
08    end
09 
10    local CommandSubstring = Message:sub(#SignalCharacters + 1)
11 
12    local Command = nil
13    local Arguments = {}
14 
15    for Match in CommandSubstring:gmatch("%w+") do
View all 32 lines...
0
Im afraid I dont quite understand what everything here does stepatron 103 — 6y
0
I recommend you check out the Wiki article I linked so you'd understand a little more! %w is the word character class, which will match an alphanumeric character, and the + quantifier matches 1 or more of the previous specifier. Avigant 2374 — 6y
Ad

Answer this question