Help me with a bug report, please!

Well, I could’t figure it out long time… Does table.insert(tab, value) work without position? It didn’t for me,.

Yes it does. If you don’t have a position, it adds value to the end of the table. What does your code look like where you’re doing the table.insert.

I found another way, where it’s fixed. You can lock this topic.

This is still not working:

function DrawPage:touched(t)
    for _,v in ipairs(self.editTools) do
        v:touched(t)
    end
    -- Drawing Tools
    if t.x>50 and t.x<WIDTH-50 and t.y>125 and t.y then
        table.insert(self.editTools, #self.editTools, DrawPage.Object(vec2(t.x, t.y)))
    end
end

When you get an error, tap it once to copy it. Then paste it here. Also, read it yourself of course.

This will allow you to write more descriptive bug reports than just “I got an error”

Since they added the stack trace, Codea error messages are usually quite helpful

Here I have made a comment. Error + code:

--[[
Error in line:

DrawPage:35: attempt to call a nil value (method 'touched')
stack traceback:
DrawPage:35: in method 'touched'
Main:22: in function 'touched'

DrawPage:35:

function DrawPage:touched(t)
    if t.x>50 and t.x<WIDTH-50 and t.y>130 and t.y<HEIGHT-50 then
        if t.state == ENDED then else
            table.insert(self.editTools, #self.editTools, DrawPage.Object(vec2(t.x, t.y)))
        end
    else --line 33
        for _,v in ipairs(self.editTools) do
            v:touched(t) -- line 35
        end
    end
end
]]

Well, when I am moving the touch outside the if loop, when I am moving and going trough the rect’s border (else, line 33) it is making the error

Well, I have accidentally deleted the project.

Cool, so the error message pretty much tells you everything you need to know. On line 35, it can’t find the method touched. That means that v, an item in the array self.editTools, does not contain an object that has the method touched. As you are using colon notation :touched, this array would normally contain instances of a class that has a touched method. So, what are you putting in self.editTools? In the table.insert you call a function DrawPage.Object, what does that function return? Does it return an object that has a method touched? If not, that’s the source of your error.

BTW I’m not a fan of mixing colon and dot notation in a single name-space (eg DrawPage:touched and DrawPage.Object), though I have sometimes done this. Some people use it as a convention, so that the dot method is for class/ static methods, and the colon method is for methods that act on an instance, but I think that’s a bit risky in Lua (too easy to call a static method as if it’s an instance method, eg self:Object)

Also instead of if t.state == ENDED then else , if t.state ~= ENDED then is easier to read.

Well, I have accidentally deleted the project.

:o

Well, that’s one way of removing bugs

XD