1. Dears, I encounter the following line in an addon:

     local frame = _G[self:GetParent():GetName():sub(1, -7)]
    

    after this line, "frame" is null variable. I think it's due to the sub(1, -7). But I find nothing about the "sub" function's syntax.

    [McArthor:] I noticed string.sub() function before, but it's of different syntax. In that addon, it's sub(number, number). But the sub() API is sub(string, number[, number]). So I'm not sure.

    [McArthor:] And, how can I debug addons in wow? for example, see the return value of self:GetParent(), GetName(), etc.

    You can look at the documentation for string.sub. The reason frame is nil is because the code is attempting to look up a global variable by name, but it does not exist. It's hard to tell you much more than that.

    Dears, I encounter the following line in an addon:

     local frame = _G[self:GetParent():GetName():sub(1, -7)]
    

    This code is the same as the following:

    local parent = self:GetParent() local name = parent:GetName() local partOfName = string.sub(name, 1, -7) local frame = _G[partOfName]

    after this line, "frame" is null variable. I think it's due to the sub(1, -7). But I find nothing about the "sub" function's syntax.

    [McArthor:] I noticed string.sub() function before, but it's of different syntax. In that addon, it's sub(number, number). But the sub() API is sub(string, number[, number]). So I'm not sure.

    They're the same function. Its being called with method syntax, so the first argument is already implicitly supplied.

    [McArthor:] And, how can I debug addons in wow? for example, see the return value of self:GetParent(), GetName(), etc.

    You can print things using the print() function as a quick method of doing this.

    Dears, I encounter the following line in an addon:

     local frame = _G[self:GetParent():GetName():sub(1, -7)]
    

    This code is the same as the following:

    local parent = self:GetParent() local name = parent:GetName() local partOfName = string.sub(name, 1, -7) local frame = _G[partOfName]

    after this line, "frame" is null variable. I think it's due to the sub(1, -7). But I find nothing about the "sub" function's syntax.

    [McArthor:] I noticed string.sub() function before, but it's of different syntax. In that addon, it's sub(number, number). But the sub() API is sub(string, number[, number]). So I'm not sure.

    They're the same function. Its being called with method syntax, so the first argument is already implicitly supplied.

    [McArthor:] And, how can I debug addons in wow? for example, see the return value of self:GetParent(), GetName(), etc.

    You can print things using the print() function as a quick method of doing this.

    The full function is as follows:

     local function savePosition(self)
        local x, y = self:GetCenter()
        x = floor(x)
        y = floor(y)
        self:ClearAllPoints()
        self:SetPoint("CENTER", UIParent, "BOTTOMLEFT", x, y)
        local parent = self:GetParent()
        print(parent)
        local name = parent:GetName()
        print(name)
        local subframe = name:sub(1, -7)
        print(subframe)
        local frame = _G[subframe]
        print(frame)
        local saved = _G[frame.savedName][frame.name]
        saved.x, saved.y = x, y
     end
    

    It prints as follows: table: 1385E840 UIParent UI nil I think "UI":sub(1, -7) makes no sense (i'm a C/C++ programmer).

    Yes, the code is just wrong. I'm not entirely sure what its supposed to do, however. I don't see a reason you can't just use the return of frame:GetName() without having to go through the parent, etc.

    Yes, the code is just wrong. I'm not entirely sure what its supposed to do, however. I don't see a reason you can't just use the return of frame:GetName() without having to go through the parent, etc.

    Yes, this codes are from an abandoned project ZHunterMod. I change its wow APIs to adapt to 4.x version. Now the only error shown in BugSack is the null "frame" due to sub(1, -7), I think.

    Yes, I understand the error but I can't divine what it was supposed to do. So I'm not sure how to help.