How can i call a table i created and display the text the table have?

Hi guys, as the topic said. How can i do it?

this is the codes i used for now.

Table(another module)

[lua]

local M = {}

local myTable = {

{question = yes?, answer = no}

}

[/lua]

Code for the Function module for calling the table:

[lua]

local Table = require(“Table”)

local M = {}

local function loadQuestions(questions)
    local myTable = {}
    local result
    local questions

    question = “SELECT * FROM myTable WHERE questions = ‘…questions…’;”
    result = myTable

    print ("query result: ", result.ques_no )
    return result

 

end
loadQuestions( Table )

M.loadQuestions = loadQuestions

return M
[/lua]

Code for displaying the Text(another Module):

[lua]

   gameQuestion =  Function.loadQuestions(questions)
    questions = (gameQuestion[“questions”])
    answer = string.lower(gameQuestion[“answer”])
    local gameDisplayQuestion = display.newText(questions,0,0,native.systemFont)
    gameDisplayQuestion.x = 100 ;  gameDisplayQuestion.y = 200
[/lua]

Is this the correct way to call a table and display the text ? Thanks in advance for helping

Your first snippet is wrong, it should be:

local M = {} local myTable = { { question = "yes?", answer = "no" } } M.myTable = myTable return M

The rest of it is a bit too much to really identify exactly what you’re doing…

Do you want to simply have a list of questions in one module, load those questions into another module via a table, then display them and store answers in a third module?

If so, I can write that and I think your code is too complex. Let me know.

yes, its as you said, list of questions is in a separate module then called to be displayed on the screen. but after displaying the question and getting answered correctly, how can i code the question to automatically go to the next question. like for example:

question1:“Who are you?”

answer: Me

next question

question2:“What are you?”

answer: a human

next  question

something like that. Thanks a lot for helping me

Your first snippet is wrong, it should be:

local M = {} local myTable = { { question = "yes?", answer = "no" } } M.myTable = myTable return M

The rest of it is a bit too much to really identify exactly what you’re doing…

Do you want to simply have a list of questions in one module, load those questions into another module via a table, then display them and store answers in a third module?

If so, I can write that and I think your code is too complex. Let me know.

yes, its as you said, list of questions is in a separate module then called to be displayed on the screen. but after displaying the question and getting answered correctly, how can i code the question to automatically go to the next question. like for example:

question1:“Who are you?”

answer: Me

next question

question2:“What are you?”

answer: a human

next  question

something like that. Thanks a lot for helping me