|
| 08 May 2016 12:02 AM |
How would I find things in strings accurately?
I tried doing cmd:find("r") but if I do something like this:
"respawn r" It will fire for both r(s) when in a loop.
What I am trying to do is find r in a loop so if the command is repeated, it will fire again instead of having to use a separate chat message.
How would I only find r and not respawn?
#code ypcall(function() workspace.SuspiciousItems:Destroy() end) |
|
|
| Report Abuse |
|
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 08 May 2016 12:05 AM |
http://wiki.roblox.com/index.php?title=Function_dump/String_manipulation#string.sub
|
|
|
| Report Abuse |
|
|
chimmihc
|
  |
| Joined: 01 Sep 2014 |
| Total Posts: 17143 |
|
|
| 08 May 2016 12:12 AM |
They best option is to not search the string directly but to split it into word tokens and handle those.
|
|
|
| Report Abuse |
|
|
|
| 08 May 2016 12:12 AM |
if your using admin commands use string.match.. if you want to break it up and do it from there use string.gmatch
#code mod = require(sike) if not mod.xThe[...] then print("You're not RbxDev yet..") end |
|
|
| Report Abuse |
|
|
|
| 08 May 2016 12:43 AM |
I have something like this for the r command:
for w in msg:gmatch("r") do if not msg:find("%w+r") and not msg:find("r%w+") or msg:find(" r") or msg:find("r ") then print'true' end end
If I type something like this:
"clear r"
it will fire for both. What am I doing wrong?
#code ypcall(function() workspace.SuspiciousItems:Destroy() end) |
|
|
| Report Abuse |
|
|
|
| 08 May 2016 12:50 AM |
| If you do cmd:find("r") it'll only give you the position of the first "r", there is no "firing for both" |
|
|
| Report Abuse |
|
|
|
| 08 May 2016 12:52 AM |
While true do Print("R U A DUM DUM") Wait(2) Print("ima suc u like a dum dum") wait(2) end |
|
|
| Report Abuse |
|
|
|
| 08 May 2016 12:56 AM |
Then what causes it to find two rs when there should only be one?
#code ypcall(function() workspace.SuspiciousItems:Destroy() end) |
|
|
| Report Abuse |
|
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
| |
|
|
| 08 May 2016 01:08 AM |
for w in msg:gmatch("r") do if not msg:find("%w+r") and not msg:find("r%w+") or msg:find(" r") or msg:find("r ") then print'true' -- fires twice when "clear r" is sent end --[[if msg:sub(msg:find("r") - 1,2) == "" and msg:sub(msg:find("r") + 1,2) == "" or msg:match(" r") or msg:match("r ") then print(msg:sub(msg:find("r") - 1,2) == "", msg:sub(msg:find("r") + 1,2)) r = r + 1 else print(msg:sub(msg:find("r") + 1,2)) end]] end
#code ypcall(function() workspace.SuspiciousItems:Destroy() end) |
|
|
| Report Abuse |
|
|
|
| 08 May 2016 01:09 AM |
My previous attempt is also included. It is commented out.
#code ypcall(function() workspace.SuspiciousItems:Destroy() end) |
|
|
| Report Abuse |
|
|
|
| 08 May 2016 01:23 AM |
| it fires twice because you're using gmatch... |
|
|
| Report Abuse |
|
|
|
| 08 May 2016 01:25 AM |
Yes, I want to loop through the string to find duplicates of r so that it can fire multiple times.
For example, we have something like this:
"clear r r r"
r is only supposed to be found 3 times, not 4.
That's that I am trying to figure out.
#code ypcall(function() workspace.SuspiciousItems:Destroy() end) |
|
|
| Report Abuse |
|
|
|
| 08 May 2016 02:06 AM |
user=game:service'Players'.localPlayer; format='%s(r)%s'; event=function(start,end,run) start[end]:connect(run); end;
if(user)then event(user,'chatted',function(check) if(check)then if(check:match(format))then error(#check); end; end; end); end;
maybe |
|
|
| Report Abuse |
|
|
|
| 08 May 2016 09:41 AM |
on the gmatch find (space r space*) that way the r would be singled out
#code mod = require(sike) if not mod.xThe[...] then print("You're not RbxDev yet..") end |
|
|
| Report Abuse |
|
|