|
| 11 Oct 2015 05:28 PM |
i want to use string.sub for when a player chats "computer start" how would i do that with the space in the message? |
|
|
| Report Abuse |
|
|
|
| 11 Oct 2015 05:29 PM |
if msg:sub(1, 14) == "computer start" then
-The [Guy] |
|
|
| Report Abuse |
|
|
rayk999
|
  |
| Joined: 18 Feb 2011 |
| Total Posts: 4705 |
|
|
| 11 Oct 2015 05:33 PM |
if msg:match("^computer start") then
Red Blossoms |
|
|
| Report Abuse |
|
|
|
| 11 Oct 2015 05:34 PM |
"i want to use string.sub"
sub ~= match
-The [Guy] |
|
|
| Report Abuse |
|
|
|
| 11 Oct 2015 05:34 PM |
match > sub :(
have a kawaii face ~ (✿◠‿◠) |
|
|
| Report Abuse |
|
|
rayk999
|
  |
| Joined: 18 Feb 2011 |
| Total Posts: 4705 |
|
|
| 11 Oct 2015 05:35 PM |
It's a much better solution considering you'd have to count the amount of characters (or do #str, but you then you waste more energy doing that)
Red Blossoms |
|
|
| Report Abuse |
|
|
|
| 11 Oct 2015 05:38 PM |
Yes. As long as OP understands the difference that it could be anywhere in the message with match as opposed to the message being exactly that text with sub.
-The [Guy] |
|
|
| Report Abuse |
|
|
rayk999
|
  |
| Joined: 18 Feb 2011 |
| Total Posts: 4705 |
|
|
| 11 Oct 2015 05:39 PM |
I put an anchor to the beginning, idiot
Red Blossoms |
|
|
| Report Abuse |
|
|
|
| 11 Oct 2015 05:43 PM |
if msg.lower:sub(1, 14) == "computer start" then
Wouldn't that be better in case they type "comPuter start" or something?
choo choo |
|
|
| Report Abuse |
|
|
|
| 11 Oct 2015 05:50 PM |
msg:lower():sub(1, 14) is what you mean
-The [Guy] |
|
|
| Report Abuse |
|
|
|
| 11 Oct 2015 05:51 PM |
@Rayk Sorry I'm not an expert in string manipulation, I didn't know what ^ meant off the top of my head.
-The [Guy] |
|
|
| Report Abuse |
|
|
Dralian
|
  |
| Joined: 21 Mar 2013 |
| Total Posts: 7624 |
|
| |
|