# How to implement the generation of buttons with answers?

**URL:** <https://forum.defold.com/t/how-to-implement-the-generation-of-buttons-with-answers/73811>\
**Category:** Questions\
**Created:** [August 14, 2023, 1:06am UTC](https://forum.defold.com/t/how-to-implement-the-generation-of-buttons-with-answers/73811 "2023-08-14T01:06:36Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![anon95708182](https://forum-defold.b-cdn.net/letter_avatar_proxy/v4/letter/a/ce7236/32.png) [@anon95708182](https://forum.defold.com/u/anon95708182)\
**Post date:** [August 15, 2023, 9:52am UTC](https://forum.defold.com/t/how-to-implement-the-generation-of-buttons-with-answers/73811/2 "2023-08-15T09:52:13Z")

</div>

Hello @Regven!

Here is what I’d do:  
Have 3 gui nodes, one text node to hold the question, a button for yes and one for no.  
Then I would use a module ([Lua modules in Defold](https://defold.com/manuals/modules/#:~:text=Defold%20allows%20you%20to%20use%20Lua%E2%80%99s%20module%20functionality,reuse%20in%20game%20object%20and%20GUI%20script%20files.)) containing a table to hold the questions and the expected answers, eg:

questions.lua

```lua
local M = {}

M.questions = {
	{"1 + 3 = 5", false},
	{"10 + 10 = 20", true},
	{"10 / 2 = 5", true},
	{"6 + 4 = 11", false},
	{"2 + 3 = 5", true},
	{"1 * 1 = 2", false},
}

return M

```

Require the file in your script and assign a local variable to it, eg like so:

local m = require “main.questions”

Then you can access question and solution like so using the number of the question:  
local question = m.questions[question\_number][1]  
local solution = m.questions[question\_number][2]

Set the text of the text node to the question.

Next get the answers:  
If “yes” is pressed:  
answer = true  
if “no” is pressed:  
answer = false

Compare answer and solution:  
if equal, the answer is correct, add one point, if not, the answer is incorrect, deduct a point.

This leaves you with the number of the question.  
I assume, you want the question to be both random and not repeating:  
Take a look here:  
[Pick random numbers without repetition - Questions - Defold game engine forum](https://forum.defold.com/t/pick-random-numbers-without-repetition/69622)

Check out the Lua manual about math.random and math.randomseed, here eg:  
[Lua 5.1 Reference Manual](http://www.lua.org/manual/5.1/manual.html#pdf-math.random)  
[Programming in Lua : 18](https://www.lua.org/pil/18.html)

---

_[View the full topic](https://forum.defold.com/t/how-to-implement-the-generation-of-buttons-with-answers/73811)._
