3.2.12 (257) accesses undefined global `collide` persistently

i was trying to catch typos in my code with __index in _G’s metatable and found the above repeated access. i suggest initializing it properly, ideally not to nil.

@RonJeffries Here’s something I wrote long ago. It lists what’s in your code and how many time it’s there. Not sure if it finds everything, so let me know if it’s missing something. Just put your project name in “project”.

viewer.mode=STANDARD

function setup()

    project="D2"
    
    textMode(CORNER)
    font("Courier")
    parameter.boolean("Include_Comments",false,setup1)
end

function setup1()
    tab,tab1={},{}
    dy,dash,per=0,0,0
    comment=false
    process()
end

function process()
    output.clear()
    local str=""
    lp=listProjectTabs(project)
    if #lp==0 then        
        return
    end
    print("Reading project list.")
    for a,b in pairs(lp) do
        print(b)
        local rp=readProjectTab(project..":"..b)
        str=str..rp
    end
    local str1=""
    for z=1,string.len(str) do
        local v=string.sub(str,z,z)
        if v=="\
" then
            comment=false
        elseif comment then
            -- ignore to end of line
        elseif v=="-" then
            dash=dash+1
            if dash==2 then
                if not Include_Comments then
                    comment=true
                end
                dash=0
            end
        elseif v>="a" and v<="z" or v>="A" and v<="Z" then
            per,dash=0,0
            str1=str1..v
        elseif str1~="" and v=="_" then
            per,dash=0,0
            str1=str1..v
        elseif str1~="" and v=="." then
            dash=0
            per=per+1
            if per==2 then
                per=0
                str1=string.sub(str1,1,string.len(str1)-1)
                if tab[str1]==nil then
                    tab[str1]=1
                else
                    tab[str1]=tab[str1]+1
                end
                str1=""
            else
                str1=str1..v
            end
        elseif v>="0" and v<="9" then
            per,dash=0,0
            str1=str1..v
        elseif str1~="" and v=="'" then
            per,dash=0,0
            str1=str1..v
        elseif str1~="" then
            per,dash=0,0
            local len=string.len(str1)
            if string.sub(str1,len,len)=="." then
                str1=string.sub(str1,1,len-1)
            end
            if string.sub(str1,len,len)=="'" then
                str1=string.sub(str1,1,len-1) 
            end 
            if tab[str1]==nil then
                tab[str1]=1
            else
                tab[str1]=tab[str1]+1
            end
            str1=""
        else
            str1=""
        end
    end
    for a,b in pairs(tab) do
        table.insert(tab1,a)
    end
    table.sort(tab1)
    showKeyboard()
    hideKeyboard()
end

function draw()
    background(40,40,50)
    fill(255)
    if #lp==0 then
        text("Project not found...  "..project,50,HEIGHT/2)
    end
    if dy==0 then
        text("Count      Name           Entries  "..#tab1,50,HEIGHT-30)
        text("Scroll up/down",WIDTH/2,HEIGHT-60)
    end
    for a,b in pairs(tab1) do
        text(string.format("%5d      %-s",tab[b],b),50,HEIGHT-50-a*20+dy)
    end
end

function touched(t)
    if t.state==CHANGED then
        dy=dy+t.deltaY
        if dy<0 then
            dy=0
        end
    end
end

interesting … i’m not sure what i’d do with it, but interesting! thanks!