Help with string.find returning the same number even with supplied 3rd arg init

This should count the number of ‘?’ in the supplied string (‘message’) and for each of those, format them into a ‘term’ which would look something like this:

string: ?t:this is a value; ?r:this is another value with a diff term!;
formatted:

{
	["t"] = "this is a value",
	["r"] = "this is a value with a diff term!"
}

From information found online and through the docs I’ve understood this should ahcive that:

for i = 1,select(2,message:gsub("?","")) do
	warn(i)
	local foundStart = string.find(message,"?",I)
	local foundEnd = string.find(message,":",i)
	print("INDEX:",foundStart,foundEnd)
	if foundStart and foundEnd then
		local term = getTerm(message:sub(foundStart+1,foundEnd-1))
		if term then
			print("TERM:",term)
			local valueEnd = string.find(message,";",i)
			print("ENDINDEX:",valueEnd)
			if valueEnd then
				local value = message:sub(foundEnd+1,valueEnd-1)
				print("VALUE:",value)
				if value then
					returnInfo[term] = value
				end
			end
		end
	end
end

Yet when I run this; I get the following output:
image
(2 should be the second value, not the first one)

I assume I’m either misunderstanding the docs or misunderstanding the use case of string.find (or maybe even another issue I failed to spot!) Any help is much appreciated, thanks.

I think you’re overcomplicating what you’re trying to do. It might be better to try rewriting the code.

Are you trying to create identifiers within a string defined by ?x:content; where x would be some identifier, and content is a substring that is associated with that identifier.

If not, what are you trying to do to this string.