View Single Post
10/14/23, 03:47 PM   #3
sinnereso
AddOn Author - Click to view addons
Join Date: Oct 2022
Posts: 247
Originally Posted by sirinsidiator View Post
Your error happens because string.find can either return 2 numbers when a result is found, or nil otherwise.
As a result, in case the name string does not contain a localization tag like ^F your code will produce an error since string.sub expects two numbers as input.
One solution would be to store the start and end values into local variables and only call sub when start is not nil:
Lua Code:
  1. local startIndex, endIndex = victomCharacterName:find("^%w+%s*")
  2. if startIndex then
  3. victomCharacterName = victomCharacterName:sub(startIndex, endIndex)
  4. end
A (imho) more elegant way would be to let the localization system take care of it for you and simply pass the name through zo_strformat:
Lua Code:
  1. victomCharacterName = zo_strformat("<<1>>", victomCharacterName)

Regardless you should never directly pass return values from one function into another unless you own them, as it's a troublesome source of future errors in case either of them changes their signature and the number of returns or input arguments changes.
For example a while ago ZOS introduced a new argument "_aSuppressCallbackHandler_" to the SetText method of the editbox. In one of my addons I simply passed the return value of another function that returned the text and some extra values since the extras would just go into the void, right? Hope you can imagine how difficult it was to figure out why the code that worked perfectly fine for years suddenly stopped working.
ya for sure.. its been tough to 100% fix. Ive been weak on these special characters anyway so I thought this would be good excercise. My issue is im not seeing anything unexpected in the error. As you can see victomCharacterName is a normal "Name^Mx" but still popped the error when 5 kills before that worked fine. I will mention There may be an issue with the new kill feed event double firing which may or may not be related. Ive had to crate a switch to not display the same even twice due to it.
  Reply With Quote