generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Accurately find things in strings?

Previous Thread :: Next Thread 
AVeryNerdyDude is not online. AVeryNerdyDude
Joined: 17 Apr 2009
Total Posts: 2163
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 is not online. 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 is not online. 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
xThe_Developer is not online. xThe_Developer
Joined: 07 Aug 2013
Total Posts: 585
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
AVeryNerdyDude is not online. AVeryNerdyDude
Joined: 17 Apr 2009
Total Posts: 2163
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
Flux_Capacitor is not online. Flux_Capacitor
Joined: 07 Apr 2008
Total Posts: 45720
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
EliteBlueSharks is not online. EliteBlueSharks
Joined: 09 Apr 2016
Total Posts: 20
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
AVeryNerdyDude is not online. AVeryNerdyDude
Joined: 17 Apr 2009
Total Posts: 2163
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 is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
08 May 2016 01:04 AM
show the code


Report Abuse
AVeryNerdyDude is not online. AVeryNerdyDude
Joined: 17 Apr 2009
Total Posts: 2163
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
AVeryNerdyDude is not online. AVeryNerdyDude
Joined: 17 Apr 2009
Total Posts: 2163
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
Flux_Capacitor is not online. Flux_Capacitor
Joined: 07 Apr 2008
Total Posts: 45720
08 May 2016 01:23 AM
it fires twice because you're using gmatch...
Report Abuse
AVeryNerdyDude is not online. AVeryNerdyDude
Joined: 17 Apr 2009
Total Posts: 2163
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
Shimotsuki is not online. Shimotsuki
Joined: 02 Apr 2016
Total Posts: 91
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
xThe_Developer is not online. xThe_Developer
Joined: 07 Aug 2013
Total Posts: 585
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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image