Need help with tables

This is my code:

CreateTopicPage = class()

function CreateTopicPage:init()
    self.text = {title = "Title here", message = "Message is here and\
new line testnction"}
    self.buttons = {"q","w","e","r","t","y","u","i","o","p","a","s","d","f","g","h","j","k","l","z","x","c","v","b","m",",",".","?", "1", "2","3","4","5","6","7", "8", "9", "0"}
    self.xy = 64
end

function CreateTopicPage:draw()
    fill(textcolor)
    font("Arial-BoldMT")
    text(self.text.title, 500, 625)
    for x = 1, 14 do
        self.buttons[x] = {}
        for y = 1, 3 do
            self.buttons[x][y] = {}
            strokeWidth(0)
            fill(255, 255, 255, 255)
            rect(x * self.xy, y * self.xy, self.xy, self.xy)
            fill(textcolor)
            text(#self.buttons, x * self.xy + self.xy/2, y * self.xy + self.xy/2)
        end
    end
end

function CreateTopicPage:touched(t)
    
end

function CreateTopicPage:keyboard(key)
    
end

I want to know how to place instead text(#self.buttons, x * self.xy + self.xy/2, y * self.xy + self.xy/2) the letters that are called in the table self.buttons = {"q","w","e","r","t","y","u","i","o","p","a","s","d","f","g","h","j","k","l","z","x","c","v","b","m",",",".","?", "1", "2","3","4","5","6","7", "8", "9", "0"}

try this

function CreateTopicPage:draw()
    fill(textcolor)
    font("Arial-BoldMT")
    text(self.text.title, 500, 625)
    local n=0  --<<<<<
    for x = 1, 14 do
        self.buttons[x] = {}
        for y = 1, 3 do
            n=n+1  --<<<<
            --self.buttons[x][y] = {}  --<<<<
            strokeWidth(0)
            fill(255, 255, 255, 255)
            rect(x * self.xy, y * self.xy, self.xy, self.xy)
            fill(textcolor)
            text(self.buttons[n], x * self.xy + self.xy/2, y * self.xy + self.xy/2)
        end
    end
end

@Ignatz it is returning now this error:

CreatePost:23: bad argument #1 to 'text' (string expected, got table)
stack traceback:
	[C]: in function 'text'
	CreatePost:23: in method 'draw'
	Main:38: in function 'draw'

@TokOut - you have to learn to debug code, yourself. Try to work out what is going wrong,

What I understand: You gave me an example where self.buttons[n] is a table but a string is expected

The reason is that you have TWO (2) tables with the name self.buttons. One has keyboard characters, the other is a table of x,y positions.

It works now, how to make now the touch? @Ignatz, Thx for help!

CreateTopicPage = class()

function CreateTopicPage:init()
    self.text = {title = "Title here", message = "Message is here and\
new line testnction"}
    self.buttons = {}
    self.letters = {"q","w","e","r","t","y","u","i","o","p","a","s","d","f","g","h","j","k","l","z","x","c","v","b","m",",",".","!","1", "2","3","4","5","6","7", "8", "9", "0","?","RET","BACK",""}
    self.xy = 64
end

function CreateTopicPage:draw()
    fill(textcolor)
    font("Arial-BoldMT")
    text(self.text.title, 500, 625)
    local n=0
    for y = 1, 3 do
        self.buttons[y] = {}
        for x = 1, 14 do
            n=n+1
            strokeWidth(0)
            fill(255, 255, 255, 255)
            rect(x * self.xy, y * self.xy, self.xy, self.xy)
            fill(textcolor)
            text(self.letters[n], x * self.xy + self.xy/2, y * self.xy + self.xy/2)
        end
    end
end

function CreateTopicPage:touched(t)
    
end

function CreateTopicPage:keyboard(key)
    
end

What don’t you understand about touch?

I mean how to specify the buttons action I know that you can make them with for x = the same as in draw, but how to make the action of them?

I’ve explained this in blog posts and my ebooks, and there are lots of posts about touch.

Please do some reading before asking someone to write the code for you. We don’t have time to explain everything to every new person. We expect you to learn what you can, then try to write the code.

Ok, where is it located?

I’ve told you more than once where my blog posts and my ebooks are

You can also search the forum

@Ignatz, this error appears by using your ebook:

Access to this link has been disabled. Please ask the owner of the shared link to send a new link to access the file or the folder.

https://coolcodea.wordpress.com/2013/06/19/index-of-posts/#more-8884

So I made a the touch function, but how to make instead if a==7 and b==2 then

Plz help, Thx!

function CreateTopicPage:touched(t)
    for y = 1, 3 do
        self.buttons[y] = {}
        for x = 1, 14 do
            if t.x>x*self.xy and t.x<x*self.xy+self.xy and t.y>y*self.xy and t.y<y*self.xy+self.xy then
                local a = x
                local b = y
                print(a .. "," .. b)
            end
        end
    end
end

Help plz!

It’s time you start helping yourself. There’s tutorials on buttons, tutorials on touch, plus plenty of examples of both of them on the forum. You’ve been on the forum for 2 months, and everything you’re asking about is just basic programming. You didn’t make a touch function, you just put a bunch of code in a function called touched(). How does the code in the question you asked relate to anything in the code you posted for touch. You want help, READ THE TUTORIALS, and practice with small programs. Once you understand the basics, you can write the programs you want without asking for help.

I am pretty sure this could be make shorter. I made it myself ;-(

function CreateTopicPage:touched(t)
    local n = 0
    for y = 1, 3 do
        self.buttons[y] = {}
        for x = 1, 14 do
            n = n + 1
            if t.x>x*self.xy and t.x<x*self.xy+self.xy and t.y>y*self.xy and t.y<y*self.xy+self.xy and t.state == BEGAN then
                local y = y
                print(x .. "," .. y)
                if x == 14 and y == 3 then
                    -- Post
                    self:post()
                elseif x == 13 and y == 3 then
                    -- Back
                    if self.selected == 1 then
                        if string.len(self.text.title)>=1 then
                            self.text.title = string.sub(self.text.title, 1, string.len(self.text.title)-1)
                        end
                    else
                        if string.len(self.text.message)>=1 then
                            self.text.message = string.sub(self.text.message, 1, string.len(self.text.message)-1)
                        else
                            self.selected = 1
                        end
                    end
                elseif x == 12 and y == 3 then
                    -- Return
                    if self.selected == 1 then
                        self.selected = 2
                    else
                        self.text.message = self.text.message .. "\
"
                    end
                else
                    if self.selected == 1 then
                        self.text.title = self.text.title .. self.letters[n]
                    else
                        self.text.message = self.text.message .. self.letters[n]
                    end
                end
            end
        end
    end
end

The nice part is : end end end end end end (6x)

Why do you keep posting chunks of code that doesn’t mean anything to anyone except you. If the code can be made shorter than make it shorter. I don’t think anyone is going to waste their time trying to do it for you.

@TokOut, it looks like you answered your own question about a=7,b=2 - which is good.

Now, making things shorter and better is a skill that can only be acquired with practice. Try it, and then when you fail, try again. At some point, if you are serious about learning to program, you will succeed.