How to create clickable links for a simple quiz?

Hello! I have a trouble to create clickable links for a simple quiz  Can you help me?

I would like to have two buttons A and B, and would like to:

  1. check which one is clicked
  2. move to another page (scene), depending A or B (ie go to correct if it is A, go to incorrect if it is B)

So far, I customized this example. But, 2) does not work well yet (ie composer.gotoScene(“dev.correct”)). Can you find an easy solution for this?

The main file (simplified) is as follows, to just show you how a module is called. Two tables are created separately to create two buttons, because they are inside two separate functions:

local buttons = require( "dev.module\_buttons" ) function()   local button\_table = {"Button A"}   buttons.buttons(sceneGroup, 1, 200, 700, 100, button\_table) end function()   local button\_table = {"Button B"}   buttons.buttons(sceneGroup, 1, 500, 700, 100, button\_table) end

The following is the called module (“dev.module_buttons”):

local composer = require( "composer" ) local scene = composer.newScene() local M = {} M.buttons = function(sceneGroup, number, x, y, size, button\_table)     local stored     local rects = {} --Store the name of the button clicked     local touchButton = function (event)       local obj = event.target       stored = obj.id       print ("STORED NUMBER: "..stored) --check which button is clicked and move to another scene, but does not work       if stored == "Button A" then         composer.gotoScene("dev.correct")       end       if stored == "Button B" then         composer.gotoScene("dev.incorrect")       end     end     --Creation of repetitive buttons     for a = 1, number, 1 do       local r = display.newText( sceneGroup, button\_table[a], 300, 660, native.systemFont, 40 )       r.x = (x \* a) + 600       r.y = y       r:addEventListener("tap",touchButton)       r.id = button\_table[a]       rects[#rects+1] = r     end end return M

Thank you!

Keep it simple…

local function onTap(event) if event.target.isCorrect then composer.gotoScene("my correct scene") else composer.gotoScene("my incorrect scene") end end local button1 = display.newText( sceneGroup, "correct", 200, 50, native.systemFont, 40 ) button1:translate(200, 700) button1:addEventListener("tap", onTap) button1.isCorrect = true local button2 = display.newText( sceneGroup, "incorrect", 200, 50, native.systemFont, 40 ) button2:translate(500, 700) button2:addEventListener("tap", onTap)

I second that, while making things modular, reuseable and flexible is the ultimate aim for a programmer, when starting out just get things working.

You can always refactor later on when you better understand how things work and where it is actually worthwhile.

Indeed. it is good to keep it simple and modular. Sometimes I complicated myself and lost. Thank you!

It would be a good idea if there are collections of simple and typical functions/techniques for Lua on the web, which can be nicely listed and easily searchable. I either see specific tutorials, or general tutorials/guides like tutorialpoint, edition, and Lua users. They are good for their purposes, but I often need somewhere in between. If anyone knows such websites, highly appreciated!

Keep it simple…

local function onTap(event) if event.target.isCorrect then composer.gotoScene("my correct scene") else composer.gotoScene("my incorrect scene") end end local button1 = display.newText( sceneGroup, "correct", 200, 50, native.systemFont, 40 ) button1:translate(200, 700) button1:addEventListener("tap", onTap) button1.isCorrect = true local button2 = display.newText( sceneGroup, "incorrect", 200, 50, native.systemFont, 40 ) button2:translate(500, 700) button2:addEventListener("tap", onTap)

I second that, while making things modular, reuseable and flexible is the ultimate aim for a programmer, when starting out just get things working.

You can always refactor later on when you better understand how things work and where it is actually worthwhile.

Indeed. it is good to keep it simple and modular. Sometimes I complicated myself and lost. Thank you!

It would be a good idea if there are collections of simple and typical functions/techniques for Lua on the web, which can be nicely listed and easily searchable. I either see specific tutorials, or general tutorials/guides like tutorialpoint, edition, and Lua users. They are good for their purposes, but I often need somewhere in between. If anyone knows such websites, highly appreciated!