i am working on command formatting right now, and for my code i have implemented this solution:
01 | -- context |
02 | local Message = ".lock true" |
03 | local SL_SETTINGS = { CommandPrefix = "." } |
04 |
05 | -- actual script |
06 | local splitMessage = Message:split( " " ) |
07 | local command = splitMessage [ 1 ] |
08 | local no_prefix = string.gsub(command, SL_SETTINGS.CommandPrefix, "" ) |
09 |
10 | print (command, no_prefix) |
11 | --> ".lock" "" |
the issue i am experiencing is that line 8 is producing a substituted string that i don't want, i get an empty string when i expect "lock"
does anybody know why this is happening and how i could fix this code?
.
is a string pattern that represents any character; therefore, it is replacing all the characters in the string.
You can use the %p
string pattern, which removes all punctuation from the string, or you can split the prefix from the string.
1 | local Message = ".lock true" |
2 | local SL_SETTINGS = { CommandPrefix = "." } |
3 |
4 | local splitMessage = Message:split( " " ) |
5 | local command = splitMessage [ 1 ] |
6 | local no_prefix = command:gsub( "%p" , "" ) -- or command:split(SL_SETTINGS.CommandPrefix)[2] |
7 |
8 | print (command, no_prefix) |
9 | --> ".lock" "lock" |