okay so if i have this text: “1 1 1 1 1 2 2 2 2”
I want a script to fire a event everytime it finds a “1” in the text
any ideas on where to start?
okay so if i have this text: “1 1 1 1 1 2 2 2 2”
I want a script to fire a event everytime it finds a “1” in the text
any ideas on where to start?
I’m not the most experienced on string manipulation, but this document should help you start. I would guess that what you’re looking for is probably string.find
. (You can read more about it in the document)
Another method of doing this would be to use the string.split()
method. For example:
local newMsg = msg:split(“ “)
for i,v in pairs(newMsg) do
if v == 1 then
— do something
end
end
Sorry about formatting
You could try something like this:
for rep in str:gmatch("1") do
-- do stuff
end
You could use gmatch:
local count = 0
for match in string.gmatch("1 1 1 1 1 2 2 2 2", "1") do -- str:gmatch("1") is another option, as shown above
count += 1-- This is specifically for counting, but you can just fire your event here as well.
end
print(count) -- 5