Front-End: Building the First Game Level

In my last post I talked about using the TileGrid option in Material-UI as a menu. This post will focus on text box elements, user input, and storing user input locally within Corona/Lua. As a reminder, I am using the Material-UI library for my front end which can be found here.

The code for the text box is included below:

textBoxResponse = mui.newTextBox({

parent = sceneGroup,
name = “response”,
labelText = “”,
text = “”,
activeColor = { 0, 0, 0, 1},
width = display.contentWidth * .95,
height = mui.getScaleVal(200),
font = native.systemFont,
fontSize = mui.getScaleVal(60),
–callBack = textListener,
x = mui.getScaleVal(320),
y = mui.getScaleVal(460),
fillColor = { 1, 1, 1 },
isEditable = true,

})

This provides an input text box for the user to type in. Then, I added a button with a buttonListener (code included below).

function buttonListener( event )

local responseText = mui.getWidgetProperty(“response”,”value”)
if responseText == “” then
else

table.insert(responsesTable,1,responseText)
table.insert(responsesDisplayTable,1,{ key = responseText, text = responseText, value = “1”, isCategory = false })

responsesCurrentCount = responsesCurrentCount + 1
responseDisplay = string.format( “%02d”, responsesCurrentCount )
responseCount.text = responseDisplay

This function is called when an “Add Response” button is clicked on the screen. There is a text box where the user can input information. Then, when they click add, I get the text from the textbox using the mui.getWidgetProperty function, the responseCount is increased by 1, the responseCount display text is changed based on the new responseCount, the response is added to the responsesTable, and the response is added to the responsesDisplayTable. The responsesTable is what will be sent to the database and the responsesDisplayTable will show all of the responses on the screen.

This is a basic implementation of allowing user input, saving the user input in a Lua table on the click of a button, and preparing a list of responses that can be used in the creation of a table.

 

Leave a Comment

Your email address will not be published. Required fields are marked *

css.php