Is there a simpler way than to pass a 40-object table? - lua
I'm running these requests for numbers with five sub-cases which have four sub-cases each. There are over 200 of these cases, of which just one is shown below, so it would be several thousand lines of code. (This is example code, the numbers would not all be the same, of course.)
elseif case1 then
if u <= 0 then if w == 0 then return B(2,3), B(3,4)
elseif w == 1 then return B(2,3), B(3,4)
elseif w == 2 then return B(2,3), B(3,4)
elseif w >= 3 then return B(2,3), B(3,4)
elseif if u == 1 then return LimitCheck(if w == 0 then return B(2,3), B(3,4)
elseif w == 1 then return B(2,3), B(3,4)
elseif w == 2 then return B(2,3), B(3,4)
elseif w >= 3 then return B(2,3), B(3,4)
elseif if u == 2 then return LimitCheck(if w == 0 then return B(2,3), B(3,4)
elseif w == 1 then return B(2,3), B(3,4)
elseif w == 2 then return B(2,3), B(3,4)
elseif w >= 3 then return B(2,3), B(3,4)
elseif if u == 3 then return LimitCheck(if w == 0 then return B(2,3), B(3,4)
elseif w == 1 then return B(2,3), B(3,4)
elseif w == 2 then return B(2,3), B(3,4)
elseif w >= 3 then return B(2,3), B(3,4)
elseif if u == 4 then return LimitCheck(if w == 0 then return B(2,3), B(3,4)
elseif w == 1 then return B(2,3), B(3,4)
elseif w == 2 then return B(2,3), B(3,4)
elseif w >= 3 then return B(2,3), B(3,4)
I thought I'd be clever and compartmentalize the code that repeats, let sub-functions take apart the cases:
local function LimitCheck(arg)
if w <= 0 then return arg[1], arg[2]
elseif w == 1 then return arg[3], arg[4]
elseif w == 2 then return arg[5], arg[6]
elseif w >= 3 then return arg[7], arg[8]
end
end
local function Limits(arg)
if u == 0 then return LimitCheck({arg[1],arg[2],arg[3],arg[4],arg[5],arg[6],arg[7],arg[8],})
elseif u == 1 then return LimitCheck({arg[9],arg[10],arg[11],arg[12],arg[13],arg[14],arg[15],arg[16],})
elseif u == 2 then return LimitCheck({arg[17],arg[18],arg[19],arg[20],arg[21],arg[22],arg[23],arg[24],})
elseif u == 3 then return LimitCheck({arg[25],arg[26],arg[27],arg[28],arg[29],arg[30],arg[31],arg[32],})
elseif u == 4 then return LimitCheck({arg[33],arg[34],arg[35],arg[36],arg[37],arg[38],arg[39],arg[40]})
end
end
And then have the main function return what it needs to know in one bulk:
elseif case1 then
return Limits({B(5,6),B(7,8), B(5,6),B(5,6), B(5,6),B(5,6), B(5,6),B(5,6),
B(5,6),B(5,6), B(5,6),B(5,6), B(5,6),B(5,6), B(5,6),B(5,6),
B(5,6),B(5,6), B(5,6),B(5,6), B(5,6),B(5,6), B(5,6),B(5,6),
B(5,6),B(5,6), B(5,6),B(5,6), B(5,6),B(5,6), B(5,6),B(5,6),
B(5,6),B(5,6), B(5,6),B(5,6), B(5,6),B(5,6), B(5,6),B(5,6)})
Problem is, this is a 40-entry table object that is passed every time, quite a bulky undertaking for a request that may happen 100 times a second. And it returns a bunch of stuff that isn't used.
I wonder if there is a resource-saving way to do this.
Here's an example of how to do this using a lookup table.
You can hardcode it or build it from code if the structure allows it.
local LUT = {
[0] = {
[0] = "a",
[1] = "b",
[2] = "c",
[3] = "d",
},
[1] = {
[0] = "e",
[1] = "f",
[2] = "g",
[3] = "h",
},
[2] = {
[0] = "i",
[1] = "j",
[2] = "k",
[3] = "l",
},
[3] = {
[0] = "m",
[1] = "n",
[2] = "o",
[3] = "p",
},
[4] = {
[0] = "q",
[1] = "r",
[2] = "s",
[3] = "t",
},
}
function lookup(u, w)
-- we only accept u <= 5
if math.type(u) ~= "integer" or u > 4
-- and w >= 0
or math.type(w) ~= "integer" or w < 0 then
return
end
return LUT[math.max(0, u)][math.min(3, w)]
end
print(lookup(-5, 3))
Related
How to fix "attempt to index ? (a number value)" ? LUA
SOLVED What I learned: When using a table within a function, make sure you don't have a variable defined under the same string/letter. Local variables overshadow global variables. Hope this helps! The error occurs on line 112 when trying to use the goto() function. I'm completely new to coding as of 4 days ago and am attempting to write a code that references a table for an argument to select a parameter for a function. I want to enter changeD(a[4]) and have checkD() run until it returns a[4]. Instead i get the error code listed in the title. My table is as follows a = {} a[1] = "north" a[2] = "east" a[3] = "south" a[4] = "west" I reference a table value as an argument in this function: function changeD(arg) local dir = 0 repeat if checkD() == arg then print("Done") dir = 1 else turn(1,1) end until dir == 1 end the checkD() function returns one of the table values. Therefore the changeD() function runs until the value returned by checkD() is the same as the table value specified in the argument. I apologize if i'm using the wrong words to refer to the table stuff as I am still wet behind the ears when it comes to coding. My full program is as follows. Sorry if its messy. c = 0 a = {} a[1] = "north" a[2] = "east" a[3] = "south" a[4] = "west" function fd(x) for i = 1 ,x do print("forward") turtle.dig() turtle.forward() end end function turn(y,x) if x == 1 then for i = 1 ,y do turtle.turnLeft() print("left") end elseif x == 2 then for i = 1 ,y do turtle.turnRight() print("right") end end end function checkD() local X, Y, Z = gps.locate() print(X) print(Y) print(Z) turtle.forward() local x , y, z = gps.locate() print(x) print(y) print(z) c = 0 result = false D = 0 repeat if c == 0 then A = X B = x print(A.." "..B) else A = Z B = z print(A.." "..B) end sleep(2) if A < B then g = 1 elseif A > B then g = 2 elseif A == B then c = 1 end print("compared values; g="..g) if c == 0 then if g == 1 then D = a[2] result = true elseif g == 2 then D = a[4] result = true end print("checked x") print(D) elseif not c == 0 then if g == 1 then D = a[3] result = true elseif g == 2 then D = a[1] result = true end print("checked z") end print("Direction facing "..D) until result == true turtle.back() return D end function changeD(arg) local dir = 0 repeat if checkD() == arg then print("Done") dir = 1 else turn(1,1) end until dir == 1 end local x = 0 function goto(x,y,z) local t = 0 local a = 0 local X, Y, Z = gps.locate() print(X) print(Y) print(Z) if X > x then t = X - x changeD(a[4]) fd(t) elseif X < x then t = x - X changeD(a[2]) fd(t) else print("cord is same") end if Z > z then t = Z - z change(a[1]) fd(t) elseif Z < z then t = z - Z change(a[3]) fd(t) else print("cord is same") end if Y > y then t = Y - y for i = 1,t do turtle.down() end elseif Y < y then t = y - Y for i = 1,t do turtle.up() end end end
In goto, you declare local a = 0. This local a variable shadows the global a = {} variable. The local a variable is a number, so can't be indexed.
How to make a general method to check for winners in Tic-Tac-Toe
I made a Tic-Tac-Toe game in Ruby. The method below checks for a winner in the vertical columns. How do I make it so that this method can be applied to boards of different sizes, like 4x4, 6x6? def vertical_check(array) result = nil if (array[0][0] == "X" && array[1][0] == "X" && array[2][0] == "X") || (array[0][1] == "X" && array[1][1] == "X" && array[2][1] == "X") || (array[0][2] == "X" && array[1][2] == "X" && array[2][2] == "X") result = "X" elsif (array[0][0] == "O" && array[1][0] == "O" && array[2][0] == "O") || (array[0][1] == "O" && array[1][1] == "O" && array[2][1] == "O") || (array[0][2] == "O" && array[1][2] == "O" && array[2][2] == "O") result = "O" else result = nil end return result end The following is a failed attempt: def vertical_check_x(array) result = nil index = 0 index2 = 0 until result != nil || index == array.length while array[index][index2] == "X" index += 1 end if index == array.length result = "X" else result = nil index = array.length end index2 += 1 end return result end def vertical_check_o(array) result = nil index = 0 index2 = 0 until result != nil || index == array.length while array[index][index2] == "O" index += 1 end if index -1 == array.length result = "O" else result = nil index = array.length end index2 += 1 end return result end def vertical_check(array) result = vertical_check_x(array) if result == nil result = vertical_check_o(array) end return result end
To quickly find a winner in given array, count the number of unique elements, confirm that there is only one unique element and if it is only X or O: def winner arr return arr[0] if arr.uniq.length == 1 && ['X', 'O'].include?(arr[0]) nil end The next problem is selecting the rows, columns and diagonals for an nxn array. Rows are easy: rows = arr.map {|row| row} Columns are as follows - you select elements with the same index for each row: cols = n.times.collect {|i| arr.map {|row| row[i]}} Next are diagonals. There are two diagonals, one starts from leftmost corner and the other from the rightmost. The leftmost diagonal has the sequence as: (0, 0) -> (1, 1) -> (2, 2) .... See the pattern? diag = n.times.collect {|i| arr[i][i]} The rightmost diagonal has pattern that goes like this (for a 3x3): (0, 2) -> (1, 1) -> (2, 0) For a 4x4, it's like this: (0, 3) -> (1, 2) -> (2, 1) -> (3, 0) So, the pattern for an nxn is: (0, n-1-0) -> (1, n-1-1) -> (2, n-1-2) -> ... (i, n-1-i) ... -> (n-1, 0) So: diag = n.times.collect {|i| arr[i][n - 1 - i]} Now, you can just do something like: w = rows.map {|r| winner r}.compact[0] for each array to get the winner.
Is there a way to add a numerical value to a variable in lua in a for loop?
I made this program: a = math.random(0, 9) - 0 -- In this stage, if the result equals zero, that means it's a match b = math.random(0, 9) - 1 c = math.random(0, 9) - 2 d = math.random(0, 9) - 3 e = math.random(0, 9) - 4 f = math.random(0, 9) - 5 g = math.random(0, 9) - 6 h = math.random(0, 9) - 7 i = math.random(0, 9) - 8 j = math.random(0, 9) - 9 print("Enter the number of trials you want to simulate.") -- This is where I decide how many trials I want to do var = io.read() a_ = 0 -- This is where I hope to keep the number of "a" matches, number of "b" matches, etc. The frequency b_ = 0 c_ = 0 d_ = 0 e_ = 0 f_ = 0 g_ = 0 h_ = 0 i_ = 0 j_ = 0 for k = 1, var do -- One loop is a trial print("Trail #"..k) if a == 0 then print("a = match") elseif a ~= 0 then print("a = not a match") end if b == 0 then print("b = match") elseif b ~= 0 then print("b = not a match") end if c == 0 then print("c = match") elseif c ~= 0 then print("c = not a match") end if d == 0 then print("d = match") elseif d ~= 0 then print("d = not a match") end if e == 0 then print("e = match") elseif e ~= 0 then print("e = not a match") end if f == 0 then print("f = match") elseif f ~= 0 then print("f = not a match") end if g == 0 then print("g = match") elseif g ~= 0 then print("g = not a match") end if h == 0 then print("h = match") elseif h ~= 0 then print("h = not a match") end if i == 0 then print("i = match") elseif i ~= 0 then print("i = not a match") end if j == 0 then print("j = match") elseif j ~= 0 then print("j = not a match") end end while true do --This is just to keep the window open after the program is done so that I can observe the data, you can ignore this end As you can see, I tried to add one to a_, b_ and c_ every time it returns a result of zero, but it doesn't work, it there a way to do this? The reason I want to do this is for an AP stats class I'm taking, and this will make it a lot easier to do. I'm just doing a_, b_, c_ for now, once I solve this issue, I'll do all of them. Thanks for reading!
Assuming you want the simulation to run 'var' times, try this: math.randomseed(os.time()) local matchStorage = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0} local randomNums = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0} local function runSimulation(numTrial) print("\nRunning trial #: " .. numTrial) for index, value in pairs(randomNums) do local variable = math.random(0, 9) randomNums[index] = variable end for index, value in pairs(randomNums) do if randomNums[index] == 0 then matchStorage[index] = matchStorage[index] + 1 print("index " .. index .. " is a match.") else print("index " .. index .. " is not a match.") end end end do print("Enter the number of trials") numTrials = io.read() for index = 1, numTrials do runSimulation(index) end print("\nRESULTS:\n") for index, value in pairs(matchStorage) do print("index " .. index .. " frequency: " .. value) end end The number of times that one of the following 'randomNum' values contain a 0 will be stored in its corresponding 'matchStorage' index.
Need Addon help fixing Name Detection in Chat
The following code is suppose to change a user name say Player in any text example: '[Player2]: Hi Player' into '[Player2]: Hi >Player<' with Player in red and >< symbols in yellow. Problem is its not detecting other players saying it and is just plain coloring them by class and warning when I say my name when it should be the other way around. I understand there is likely Global Leaks and such as this is a beta phase addon at the moment and I am constantly working on rewriting functions to make them better but for now I am trying to get everything working first. If you can simplify the Name detection and change it without messing with links in WoW I would take the advice and I will throw a comment line in the code to show your name for credit and in the main addon page. Otherwise I just need the fix to find out why its not working as intended. Here is the code: local _PlayerName2 = CM2.StripSpecial(UnitName("player"), true) _PlayerName2 = _PlayerName2:lower() local _PlayerName, _ = UnitName("player") --Detect if the current character said their own name. Block Warnings. local throwWarn = true if ChatAuthor == curPlayer then --Player said something. throwWarn = false --CM2.Print("Disabled Warnings") end if text == nil then print("Text Nil, Check URL Detection Code") end --Color own name in your chat. Really only sender name because all other references will --be tied to the alert. if throwWarn == false and text:find(" "..curPlayer.." ") ~= nil then text = CM2.far(text, curPlayer, CM2.ColorName(CM2_Nick[plainPlayerName][2], plainPlayerName)) end if throwWarn == false and text:find(case_insensitive_pattern(plainPlayerName)) ~= nil then text = CM2.far(text, plainPlayerName, CM2.ColorName(CM2_Nick[plainPlayerName][2], plainPlayerName)) end --Detect and alert when playername is spoken local pos = 0 if throwWarn == true and text:find(" ".._PlayerName.." ") ~= nil then --Detect if the Original Player name was said. text = text:gsub(" ".._PlayerName.." ", " "..CHATMOD_COLOR["YELLOW"]..">"..CHATMOD_COLOR["RED"].._PlayerName..CHATMOD_COLOR["YELLOW"].."<\124r ") UIErrorsFrame:AddMessage(text, red, green, blue, nil, UIERRORS_HOLD_TIME) PlaySound("FriendJoinGame") elseif throwWarn == true and text:find(" "..case_insensitive_pattern(plainPlayerName).." ") ~= nil then --Detect if the stripped down Player Name was said. text = text:gsub(" ".._PlayerName2.." ", " "..CHATMOD_COLOR["YELLOW"]..">"..CHATMOD_COLOR["RED"].._PlayerName2..CHATMOD_COLOR["YELLOW"].."<\124r ") UIErrorsFrame:AddMessage(text, red, green, blue, nil, UIERRORS_HOLD_TIME) PlaySound("FriendJoinGame") end if text == nil then print("Text Nil, Check playername highlighter Code") end -- Color Nicks if CM2_Options["ColorNicks"] then -- Hold Original unmodified words for later use temp2 = text temp2 = CM2.StripSpecial(temp2) temp = CM2.StripSpecial(text) temp = string.gsub(temp, "%]%[", " ") temp = string.gsub(temp, "[^a-zA-Z0-9%s]", "") words = CM2.GetWords(temp) words2 = CM2.GetWords(temp:lower()) for word = 1, #words do -- Cant be the player name or it locks up the client... Go figure... if words[word] ~= UnitName("player") and words[word] ~= plainPlayerName then --print(words[word]:lower()) if CM2_Nick[words[word]:lower()] ~= nil then --{level, class, guild, realm, name} Nick Layout. Name is the unfiltered name. local newWord = CM2.ColorName(CM2_Nick[words[word]:lower()][2], words[word]:lower()) word2find = words[word] pos = temp2:find(word2find) or temp:find(words2[word]) if newWord ~= nil then --replace with find code. text = CM2.far(text, word2find, newWord) end end end end end Function CM2.far: function CM2.far(str, fstr, rstr) if (str and type(str) == "string") and (fstr and type(fstr) == "string") and (rstr and type(rstr) == "string") then --And space at the end so gfind will find till the end. --In case a match is there. str = str .. " " local pos = nil for x in str:gmatch("[^%:]"..case_insensitive_pattern(fstr).."[^%:]") do if pos ~= nil and pos ~= str:find("[^%:]"..case_insensitive_pattern(fstr).."[^%:]", pos+1) then str = str:sub(1, pos) .. rstr .. str:sub(pos + #fstr + 1) --print(str) pos = str:find("[^%:]"..case_insensitive_pattern(fstr).."[^%:]", pos+1) elseif pos == nil then pos = str:find("[^%:]"..case_insensitive_pattern(fstr).."[^%:]") str = str:sub(1, pos) .. rstr .. str:sub(pos + #fstr + 1) pos = str:find("[^%:]"..case_insensitive_pattern(fstr).."[^%:]", pos+1) --print(str) end end str = str:sub(1, #str - 1) return str end end Function CM2.StripSpecial: function CM2.StripSpecial(msg, player) PlayerStripped = 0 --Strips out all special characters such as Ö and the like. --Should only be used for being returned to a temp string unless replacement is required. if msg ~= nil and type(msg) == "string" then for x=1, #msg do local CharVal = string.byte(string.sub(msg,x,x+1), -1) --local StrTab = {} --for a=1, #msg do -- StrTab:Insert( --print("Debug: "..string.byte(string.sub(msg,x,x+1))) --print(CharVal) if CharVal ~= nil then if 146 <= CharVal and CharVal <= 150 then msg = StringReplace(msg, x, "O") if player then PlayerStripped = PlayerStripped + 1 end elseif 178 <= CharVal and CharVal <= 182 then msg = StringReplace(msg, x, "o") if player then PlayerStripped = PlayerStripped + 1 end elseif 128 <= CharVal and CharVal <= 134 then msg = StringReplace(msg, x, "A") if player then PlayerStripped = PlayerStripped + 1 end elseif 160 <= CharVal and CharVal <= 166 then msg = StringReplace(msg, x, "a") if player then PlayerStripped = PlayerStripped + 1 end elseif 136 <= CharVal and CharVal <= 139 then msg = StringReplace(msg, x, "E") if player then PlayerStripped = PlayerStripped + 1 end elseif 168 <= CharVal and CharVal <= 171 then msg = StringReplace(msg, x, "e") if player then PlayerStripped = PlayerStripped + 1 end elseif 153 <= CharVal and CharVal <= 156 then msg = StringReplace(msg, x, "U") if player then PlayerStripped = PlayerStripped + 1 end elseif 185 <= CharVal and CharVal <= 188 then msg = StringReplace(msg, x, "u") if player then PlayerStripped = PlayerStripped + 1 end elseif 140 <= CharVal and CharVal <= 143 then msg = StringReplace(msg, x, "I") if player then PlayerStripped = PlayerStripped + 1 end elseif 172 <= CharVal and CharVal <= 175 then msg = StringReplace(msg, x, "i") if player then PlayerStripped = PlayerStripped + 1 end elseif 135 == CharVal then msg = StringReplace(msg, x, "C") if player then PlayerStripped = PlayerStripped + 1 end elseif 167 == CharVal then msg = StringReplace(msg, x, "c") if player then PlayerStripped = PlayerStripped + 1 end elseif 144 == CharVal then msg = StringReplace(msg, x, "D") if player then PlayerStripped = PlayerStripped + 1 end elseif 176 == CharVal then msg = StringReplace(msg, x, "o") if player then PlayerStripped = PlayerStripped + 1 end elseif 152 == CharVal then msg = StringReplace(msg, x, "O") if player then PlayerStripped = PlayerStripped + 1 end elseif 184 == CharVal then msg = StringReplace(msg, x, "o") if player then PlayerStripped = PlayerStripped + 1 end end end end end return msg end Function CM2.GetWords: function CM2.GetWords(str) if type(str) == "string" then local results = {} for word in string.gmatch(str, "%S+", 9) do table.insert(results, word) end return results end end Function case_insensitive_pattern: function case_insensitive_pattern(pattern) -- find an optional '%' (group 1) followed by any character (group 2) local p = pattern:gsub("(%%?)(.)", function(percent, letter) --print(percent, letter) if percent ~= "" or (not letter:match("%a")) then if letter ~= "-" then -- if the '%' matched, or `letter` is not a letter, return "as is" return percent .. letter elseif letter == "-" then return "%-" end else if letter == "[" then return "%[" elseif letter == "]" then --print("hi") return "%]" end -- else, return a case-insensitive character class of the matched letter return string.format("[%s%s]", letter:lower(), letter:upper()) end end) return p end Function CM2.ColorName: function CM2.ColorName(str, word) --Using the class and word provided precolor it for chat. if str == "MONK" then word = "\124cff00ff96" .. CM2_Nick[word][5] .. "|r" elseif str == "DEATH KNIGHT" then word = "\124cffc41f3b" .. CM2_Nick[word][5] .. "|r" elseif str == "DRUID" then word = "\124cffff7d0a" .. CM2_Nick[word][5] .. "|r" elseif str == "HUNTER" then word = "\124cffabd473" .. CM2_Nick[word][5] .. "|r" elseif str == "MAGE" then word = "\124cff69ccf0" .. CM2_Nick[word][5] .. "|r" elseif str == "PALADIN" then word = "\124cfff58cba" .. CM2_Nick[word][5] .. "|r" elseif str == "PRIEST" then word = "\124cffffffff" .. CM2_Nick[word][5] .. "|r" elseif str == "ROGUE" then word = "\124cfffff569" .. CM2_Nick[word][5] .. "|r" elseif str == "SHAMAN" then word = "\124cff0070de" .. CM2_Nick[word][5] .. "|r" elseif str == "WARLOCK" then word = "\124cff9482c9" .. CM2_Nick[word][5] .. "|r" elseif str == "WARRIOR" then word = "\124cffc79c6e" .. CM2_Nick[word][5] .. "|r" end return word end Edit 1: Managed to fix self name warning but noticed that saying your full matching player name in chat is not being colored. I can deal with this myself. No changes we able to be made yet to fix the other players saying the players name warning yet.
Issue with lua code in world of warcraft
-- Color Nicks if CM2_Options["ColorNicks"] then -- Hold Original unmodified words for later use local temp2 = ChatMod2_GetWords(text) local temp = ChatMod2_StripSpecial(text) temp = string.gsub(temp, "[^a-zA-Z0-9%s]", "") temp = temp:lower() local words = ChatMod2_GetWords(temp) for word = 1, #words do -- Cant be the player name or it locks up the client... Go figure... if words[word] ~= UnitName("player") then print(temp) if CM2_Nick[words[word]] ~= nil then --{level, class, guild, realm, name} Nick Layout. Name is the unfiltered name. local newWord = ChatMod2_ColorName(CM2_Nick[words[word]][2], words[word]) text = text:gsub(temp2[word], newWord) end end end end The above is causing World Of Warcraft to fail to load into the game. Because I lack the debugging ability from the program itself does anyone see why here? Below are the other functions mentioned in the above code: function ChatMod2_GetWords(str) local results = {} for word in string.gmatch(str, "%S+", 9) do table.insert(results, word) end return results end function ChatMod2_ColorName(str, word) --Using the class and word provided precolor it for chat. if str == "MONK" then word = "\124cff00ff96" .. CM2_Nick[word][5] .. "|r" elseif str == "DEATH KNIGHT" then word = "\124cffc41f3b" .. CM2_Nick[word][5] .. "|r" elseif str == "DRUID" then word = "\124cffff7d0a" .. CM2_Nick[word][5] .. "|r" elseif str == "HUNTER" then word = "\124cffabd473" .. CM2_Nick[word][5] .. "|r" elseif str == "MAGE" then word = "\124cff69ccf0" .. CM2_Nick[word][5] .. "|r" elseif str == "PALADIN" then word = "\124cfff58cba" .. CM2_Nick[word][5] .. "|r" elseif str == "PRIEST" then word = "\124cffffffff" .. CM2_Nick[word][5] .. "|r" elseif str == "ROGUE" then word = "\124cfffff569" .. CM2_Nick[word][5] .. "|r" elseif str == "SHAMAN" then word = "\124cff0070de" .. CM2_Nick[word][5] .. "|r" elseif str == "WARLOCK" then word = "\124cff9482c9" .. CM2_Nick[word][5] .. "|r" elseif str == "WARRIOR" then word = "\124cffc79c6e" .. CM2_Nick[word][5] .. "|r" end return word end function ChatMod2_StripSpecial(msg) --Strips out all special characters such as Ö and the like. --Should only be used for being returned to a temp string unless replacement is required. if msg ~= nil and type(msg) == "string" then for x=1, #msg do local CharVal = string.byte(string.sub(msg,x,x+1), -1) --local StrTab = {} --for a=1, #msg do -- StrTab:Insert( --print("Debug: "..string.byte(string.sub(msg,x,x+1))) --print(CharVal) if CharVal ~= nil then if 146 <= CharVal and CharVal <= 150 then msg = StringReplace(msg, x, "O") elseif 178 <= CharVal and CharVal <= 182 then msg = StringReplace(msg, x, "o") elseif 128 <= CharVal and CharVal <= 134 then msg = StringReplace(msg, x, "A") elseif 160 <= CharVal and CharVal <= 166 then msg = StringReplace(msg, x, "a") elseif 136 <= CharVal and CharVal <= 139 then msg = StringReplace(msg, x, "E") elseif 168 <= CharVal and CharVal <= 171 then msg = StringReplace(msg, x, "e") elseif 153 <= CharVal and CharVal <= 156 then msg = StringReplace(msg, x, "U") elseif 185 <= CharVal and CharVal <= 188 then msg = StringReplace(msg, x, "u") elseif 140 <= CharVal and CharVal <= 143 then msg = StringReplace(msg, x, "I") elseif 172 <= CharVal and CharVal <= 175 then msg = StringReplace(msg, x, "i") elseif 135 == CharVal then msg = StringReplace(msg, x, "C") elseif 167 == CharVal then msg = StringReplace(msg, x, "c") elseif 144 == CharVal then msg = StringReplace(msg, x, "D") elseif 176 == CharVal then msg = StringReplace(msg, x, "o") elseif 152 == CharVal then msg = StringReplace(msg, x, "O") elseif 184 == CharVal then msg = StringReplace(msg, x, "o") end end end end return msg end I appreciate any and all help.
ChatMod2_GetWords is clearly fine. ChatMod2_ColorName on the other hand will explode if CM2_Nick doesn't have a word entry or if that entry doesn't have an index 5. I haven't looked at ChatMod2_StripSpecial much yet.