Wordle Comparison System Help

I have two words, one being the players guess and one being the actual word.
Lets say the actual word is “WATER”.
Lets say the players guess is “WAATR”

How could I compare the two words so that if the player guess letter is in the same position as the actual word letter it will be green.
If the letter is in the actual word but at a different index then it will be orange.
If the letter doesn’t exist at all in the word it will be white.

So in this scenario it will be Green, Green, White, Orange, Green.

I have tried placing each letter into a table and iterating through but its getting a little confusing.

Maybe someone with a clear mind could offer support. Thanks.

Well, since I don’t have any information on your display system, I’ll just wing it:

local function guessWord(word,guess,frame)
   local findList = string.split(string.toUpper(word),"")
   local guessList = string.split(string.toUpper(guess),"")
   --initialize outputColors, since you're dealing with non-5 letter words.
   local outputColors = {}
   for i=1,#findList do
      table.insert(outputColors,"white")
   end
   --get greens
   for v,i in pairs(guessList) do
      if findList[v] == i then
          outputColors[v] = "green"
          findList[v] = nil
      end
   end
   --now handle yellows
   for v,i in pairs(guessList) do
      local idx = table.find(findList,i)
      if idx then
          outputColors[v] = "orange"
          findList[idx] = nil
      end
   end
   for v,i in pairs(outputColors) do
      local change = frame:FindFirstChild(v).TextLabel
     change.Text = guessList[v]
      if i == "green" then
          change.TextColor3 = Color3.fromRGB(134, 255, 107)
      elseif i == "orange" then
          change.TextColor3 = Color3.fromRGB(255, 182, 99)
      else
          change.TextColor3 = Color3.fromRGB(255, 255, 255)
      end
   end
end

This should do what you’re asking, but better than what I had posted earlier, and should work with your system.

1 Like
local function fillBoxes(frame, word, guess, correct)
	local highWord = string.upper(word)
	local highGuess = string.upper(guess)
	local wordList = {}
	local guessList = {}
	local correctWrongTable = {}
	
	for i = 1, #word do
		wordList[i] = tostring(string.char(string.byte(highWord, i, i)))
	end
	print(wordList)
	
	for i = 1, #guess do
		guessList[i] = tostring(string.char(string.byte(highGuess, i, i)))
	end
	print(guessList)
	
	for i = 1, #wordList, 1 do
		for v = 1, #guessList, 1 do
			if i == v then
				if wordList[i] == guessList[i] then
					correctWrongTable[i] = "correct"
					i += 1
				end
			end
			if wordList[i] == guessList[v] then
				correctWrongTable[i] = "exists"
				i+=1
			end
			if correctWrongTable[i] == nil then
				correctWrongTable[i] = "wrong"
			end
		end
	end

        for i = 1, #guessList, 1 do
		frame:FindFirstChild(i).TextLabel.Text = tostring(guessList[i])
	end
	
	for i = 1, #guessList, 1 do
		if correctWrongTable[i] == "correct" then
			frame:FindFirstChild(i).TextLabel.TextColor3 = Color3.fromRGB(134, 255, 107)
		elseif correctWrongTable[i] == "exists" then
			frame:FindFirstChild(i).TextLabel.TextColor3 = Color3.fromRGB(255, 182, 99)
		elseif correctWrongTable[i] == "wrong" then
			frame:FindFirstChild(i).TextLabel.TextColor3 = Color3.fromRGB(255, 255, 255)
		end
	end
end

This is the entire function, it displays it to a GUI on the players screen, the gui is split into x amount of boxes each numbered 1 - x.

In this case the word was “EAR” and I entered “ERB”, B should have been white as it isnt in the word “Ear” and R should have been orange as is in the wrong index.
image

Your reply just came through as I posted, I’ll try it now @TheB4dComputer

To add on to this, in order to split words into a table of letters, you can use string.split.

string.split Documentation

string | Documentation - Roblox Creator Hub

can become

local word = "water" 
local findList = string.split(word, "")
local guess = "waatr"
local guessList = string.split(guess, "")

Never mind disregard this, I can see you already made a system for this, although this way may be easier than using string.char and string.byte.

1 Like

Yeah, I was assuming he already had a system for that, so I didn’t bother looking anything up. I’ll update my code with this. Thanks!

1 Like

Just in case you didn’t see, I rewrote the code again so it should work for your system.

	--now handle yellows
	for v,i in pairs(guessList) do
		local idx = table.find(wordList, guessList[v])
		print(idx)
		if idx then
			correctWrongTable[v] = "orange"
			wordList[idx] = nil
		end
	end

So I adjusted this part so as your table.find bit wasnt getting the letter from the list. But IDX is printing nil?

wordList =
image
guessList =
image
outputColors =
image

interesting

omg wait i think its cuz im not using a table :joy:
edit: its still nil?

Ahh, my bad! I forgot to mention this: I make sure you don’t get false greens or oranges by changing a match in the wordList to nil. So, to guess again, you’d have to reset the wordList, which you already know how to do.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.