1

Basically I have a for loop that is creating variables based on data in a database, I then have an event listener that is also created based on the for loop and I want to know which text is pressed

Ive tried events in the function, creating a variable for my row.name etc.

for row in db:nrows( "SELECT * FROM Students WHERE Class = '"..class.."'" ) do
        print(row.Name)
        --track how many students there are 
        count = count+1
        --When displaying the names, put them in line, if they go below 1000 y level, move to the right and go down again
        ny = ny + 80
        if (ny == 1000) then
            nx = nx + 300
            ny = 280
        end
        -- Display students
        student[row] = display.newText( sceneGroup, row.Name, nx, ny, native.systemFont, 30 )
        --Make a button for every student in the row that goes to studentscene function
        student[row]:addEventListener( "tap", studentscene)
    end

The function then looks like

local function studentscene()
    composer.gotoScene( "student", { time=800, effect="crossFade" } )
end

I want to be able to track which student name was pressed, yet i cannot find a way to do so. I need this so I can track in the database which name it is so I can display their information

  • you can use the `event.x` and `event.y` to determine students count value, assuming your db is in still in the same order as when you made the display you can get the same row, using something like this: https://stackoverflow.com/questions/16568/how-to-select-the-nth-row-in-a-sql-database-table – Nifim May 16 '19 at 23:05
  • I dont need to know the students count value but rather what student value is clicked, so nothing to do with the database but rather the variables – Lua Enthusiast May 16 '19 at 23:33
  • oh, to do that just use `self` to access the text object and get the value of the text field that was set to `row.name` – Nifim May 17 '19 at 00:53
  • 2
    `local function studentscene(event) local name = event.target.text; ... end` – Egor Skriptunoff May 17 '19 at 07:38

1 Answers1

0

you can add it by using params in goto function

    `options = {
       effect = model,
       time = time,
       params = params,
    }
composer.gotoScene( nextScene , options )`

for example do this params = {student="mohsen"} and in scene:show function do this :

if event.params then

studen = event.params.name
end
Mohsen
  • 13
  • 4