Hi guys,
So I have a few scenes and on each scene I have a list of radio buttons, and when one is clicked then onpress of the next button it sets a value in myData.lua now the issue is once one button has set the value on any of the other pages if a different radio button is clicked it doesn’t change the value it stays as the first on clicked.
Here are two of my scenes, really need help.
[lua]
–
– incidentReportingPg1.lua
–
local composer = require( “composer” )
local scene = composer.newScene()
local widget = require( “widget” )
local myData = require( “myData” )
local function btnPrevious( event )
composer.gotoScene( “incidentReportingPg6”, { effect=“slideRight”, time=800} )
end
function scene:create( event )
local sceneGroup = self.view
print( myData.IRb4 )
–bg
local bg = display.newRect( 0, 0, display.contentWidth, display.contentHeight )
bg.anchorX = 0
bg.anchorY = 0
bg:setFillColor( 0.9, 0.9, 0.9 ) – white
sceneGroup:insert( bg )
–titleHeader
local titleHeader = display.newImage( “titleHeader.png” )
titleHeader:translate( 160, -22 )
–title
local title = display.newText( “Incident Reporting”, 0, 0, native.systemFont, 32 )
title:setFillColor( 0 ) – black
title.x = display.contentWidth * 0.5
title.y = -25
–textPage
local textPage = display.newText(“Page 7”,
280,130, display.contentWidth -25 , display.contentHeight * 0.5, native.systemFont, 15 )
textPage:setFillColor( 0, 0, 0 )
–textWhatWas
local textWhatWas = display.newText(“What was the cause of the incident? (1 of 5)”,
172, 150, display.contentWidth, display.contentHeight * 0.5, native.systemFont, 20 )
textWhatWas:setFillColor( 0, 0, 0 )
sceneGroup:insert( textWhatWas )
–textSlips
local textSlips = display.newText(“Slips, trip or fall on the same level”,
212, 219, display.contentWidth, display.contentHeight * 0.5, native.systemFont, 13 )
textSlips:setFillColor( 0, 0, 0 )
sceneGroup:insert( textSlips )
–textFallFrom
local textFallFrom = display.newText(“Fall from Height”,
212, 280, display.contentWidth, display.contentHeight * 0.5, native.systemFont, 13 )
textFallFrom:setFillColor( 0, 0, 0 )
sceneGroup:insert( textFallFrom )
–textBoxHeight
local textBoxHeight = native.newTextField( 200, 166, 75, 40 )
textBoxHeight.size = 20
textBoxHeight:addEventListener( “userInput”, textBoxHeight )
textBoxHeight.inputType = “number”
sceneGroup:insert( textBoxHeight )
–textInMeters
local textInMeters = display.newText(“In Meters”,
410, 280, display.contentWidth, display.contentHeight * 0.5, native.systemFont, 13 )
textInMeters:setFillColor( 0, 0, 0 )
sceneGroup:insert( textInMeters )
–textInjured
local textInjured = display.newText(“Injured whilst handling, lifting or carrying”,
212, 341, display.contentWidth, display.contentHeight * 0.5, native.systemFont, 13 )
textInjured:setFillColor( 0, 0, 0 )
sceneGroup:insert( textInjured )
–textHit
local textHit = display.newText(“Hit by an object”,
212, 402, display.contentWidth, display.contentHeight * 0.5, native.systemFont, 13 )
textHit:setFillColor( 0, 0, 0 )
sceneGroup:insert( textHit )
–textContact
local textContact = display.newText(“Contact with an object”,
212, 463, display.contentWidth, display.contentHeight * 0.5, native.systemFont, 13 )
textContact:setFillColor( 0, 0, 0 )
sceneGroup:insert( textContact )
–textMore
local textMore = display.newText("**More options are available on the next page**",
180, 500, display.contentWidth, display.contentHeight * 0.5, native.systemFont, 13 )
textMore:setFillColor( 0, 0, 0 )
sceneGroup:insert( textMore )
– Image sheet options and declaration
local options = {
width = 26,
height = 26,
numFrames = 2,
sheetContentWidth = 26,
sheetContentHeight = 52
}
local checkboxSheet = graphics.newImageSheet( “checkboxSheet.png”, options )
– Create a group for the radio button set
local radioGroup = display.newGroup()
– Create two associated radio buttons (inserted into the same display group)
local radioButton1 = widget.newSwitch
{
left = 20,
top = 92,
style = “radio”,
id = “RadioButton1”,
width = 26,
height = 26,
onPress = onSwitchPress,
sheet = checkboxSheet,
frameOff = 1,
frameOn = 2
}
radioGroup:insert( radioButton1 )
sceneGroup:insert( radioButton1 )
local radioButton2 = widget.newSwitch
{
left = 20,
top = 153,
style = “radio”,
id = “RadioButton2”,
width = 26,
height = 26,
onPress = onSwitchPress,
sheet = checkboxSheet,
frameOff = 1,
frameOn = 2
}
radioGroup:insert( radioButton2 )
sceneGroup:insert( radioButton2 )
local radioButton3 = widget.newSwitch
{
left = 20,
top = 214,
style = “radio”,
id = “RadioButton2”,
width = 26,
height = 26,
onPress = onSwitchPress,
sheet = checkboxSheet,
frameOff = 1,
frameOn = 2
}
radioGroup:insert( radioButton3 )
sceneGroup:insert( radioButton3 )
local radioButton4 = widget.newSwitch
{
left = 20,
top = 275,
style = “radio”,
id = “RadioButton2”,
width = 26,
height = 26,
onPress = onSwitchPress,
sheet = checkboxSheet,
frameOff = 1,
frameOn = 2
}
radioGroup:insert( radioButton4 )
sceneGroup:insert( radioButton4 )
local radioButton5 = widget.newSwitch
{
left = 20,
top = 336,
style = “radio”,
id = “RadioButton2”,
width = 26,
height = 26,
onPress = onSwitchPress,
sheet = checkboxSheet,
frameOff = 1,
frameOn = 2
}
radioGroup:insert( radioButton5 )
sceneGroup:insert( radioButton5 )
local function OnbtnNext( event )
if event.phase == “ended” then
local radioOn = false
local textFilled = true
myData.fallHeight = textBoxHeight.text
if radioButton1.isOn == true then
myData.IRb4 = textSlips.text
end
if radioButton2.isOn == true then
myData.IRb4 = textFallFrom.text
radioOn = true
end
if radioButton3.isOn == true then
myData.IRb4 = textInjured.text
end
if radioButton4.isOn == true then
myData.IRb4 = textHit.text
end
if radioButton5.isOn == true then
myData.IRb4 = textContact.text
end
if textBoxHeight.text == “” or textBoxHeight.text == nil then
textFilled = false
end
if radioOn == true and textFilled then
composer.gotoScene( “incidentReportingPg8”, { effect=“slideLeft”, time=800,} )
end
if radioOn == true and textFilled == false then
local msg
if textFilled == false then
msg = “No input in textbox”
end
local alert = native.showAlert( “Warning”, "ERROR: "…msg, { “OK” }, onComplete)
end
if radioOn == false and textFilled == false then
composer.gotoScene( “incidentReportingPg8”, { effect=“slideLeft”, time=800,} )
end
end
return true
end
–btnPrevious
local btnPrevious = widget.newButton
{
width = 150,
height = 40,
defaultFile = “btnPrevious.png”,
onEvent = btnPrevious
}
btnPrevious.x = 84
btnPrevious.y = 445
–btnNext
local btnNext = widget.newButton
{
width = 150,
height = 40,
defaultFile = “btnNext.png”,
onEvent = OnbtnNext
}
btnNext.x = 235
btnNext.y = 445
–sceneGroup
sceneGroup:insert( titleHeader )
sceneGroup:insert( title )
sceneGroup:insert( textPage )
sceneGroup:insert( btnNext )
sceneGroup:insert( btnPrevious )
end
function scene:show( event )
local sceneGroup = self.view
end
function scene:hide( event )
local sceneGroup = self.view
end
function scene:destroy( event )
local sceneGroup = self.view
end
– Listener setup
scene:addEventListener( “create”, scene )
scene:addEventListener( “show”, scene )
scene:addEventListener( “hide”, scene )
scene:addEventListener( “destroy”, scene )
return scene
[/lua]
[lua]
–
– incidentReportingPg1.lua
–
local composer = require( “composer” )
local scene = composer.newScene()
local widget = require( “widget” )
local myData = require( “myData” )
local function btnNext( event )
composer.gotoScene( “incidentReportingPg9”, { effect=“slideLeft”, time=800} )
end
local function btnPrevious( event )
composer.gotoScene( “incidentReportingPg7”, { effect=“slideRight”, time=800} )
end
function scene:create( event )
local sceneGroup = self.view
print( myData.IRb4 )
–bg
local bg = display.newRect( 0, 0, display.contentWidth, display.contentHeight )
bg.anchorX = 0
bg.anchorY = 0
bg:setFillColor( 0.9, 0.9, 0.9 ) – white
sceneGroup:insert( bg)
–titleHeader
local titleHeader = display.newImage( “titleHeader.png” )
titleHeader:translate( 160, -22 )
–title
local title = display.newText( “Incident Reporting”, 0, 0, native.systemFont, 32 )
title:setFillColor( 0 ) – black
title.x = display.contentWidth * 0.5
title.y = -25
–textPage
local textPage = display.newText(“Page 8”,
280, 130, display.contentWidth -25 , display.contentHeight * 0.5, native.systemFont, 15 )
textPage:setFillColor( 0, 0, 0 )
–textWhatWas
local textWhatWas = display.newText(“What was the cause of the incident? (2 of 5)”,
172, 150, display.contentWidth, display.contentHeight * 0.5, native.systemFont, 20 )
textWhatWas:setFillColor( 0, 0, 0 )
sceneGroup:insert( textWhatWas )
–textVehicleOff
local textVehicleOff = display.newText(“Vehicle road traffic incident (off campus)”,
212, 220, display.contentWidth, display.contentHeight * 0.5, native.systemFont, 13 )
textVehicleOff:setFillColor( 0, 0, 0 )
sceneGroup:insert( textVehicleOff )
–textVehicleOn
local textVehicleOn = display.newText(“Vehicle road traffic incident (on campus)”,
212, 281, display.contentWidth, display.contentHeight * 0.5, native.systemFont, 13 )
textVehicleOn:setFillColor( 0, 0, 0 )
sceneGroup:insert( textVehicleOn )
–textIncidentInvolving
local textIncidentInvolving = display.newText(“Incident involving a bicycle(s)”,
212, 342, display.contentWidth, display.contentHeight * 0.5, native.systemFont, 13 )
textIncidentInvolving:setFillColor( 0, 0, 0 )
sceneGroup:insert( textIncidentInvolving )
–textAssaulted
local textAssaulted = display.newText(“Assaulted by another person”,
212, 403, display.contentWidth, display.contentHeight * 0.5, native.systemFont, 13 )
textAssaulted:setFillColor( 0, 0, 0 )
sceneGroup:insert( textAssaulted )
–textWorkRelated
local textWorkRelated = display.newText(“Work related upper limb disorder (e.g. RSI)”,
212, 464, display.contentWidth, display.contentHeight * 0.5, native.systemFont, 13 )
textWorkRelated:setFillColor( 0, 0, 0 )
sceneGroup:insert( textWorkRelated )
–textMore
local textMore = display.newText("**More options are available on the next page**",
180, 500, display.contentWidth, display.contentHeight * 0.5, native.systemFont, 13 )
textMore:setFillColor( 0, 0, 0 )
sceneGroup:insert( textMore )
– Image sheet options and declaration
local options = {
width = 26,
height = 26,
numFrames = 2,
sheetContentWidth = 26,
sheetContentHeight = 52
}
local checkboxSheet = graphics.newImageSheet( “checkboxSheet.png”, options )
– Create a group for the radio button set
local radioGroup = display.newGroup()
– Create two associated radio buttons (inserted into the same display group)
local radioButton1 = widget.newSwitch
{
left = 20,
top = 92,
style = “radio”,
id = “RadioButton1”,
width = 26,
height = 26,
onPress = onSwitchPress,
sheet = checkboxSheet,
frameOff = 1,
frameOn = 2
}
radioGroup:insert( radioButton1 )
sceneGroup:insert( radioButton1 )
local radioButton2 = widget.newSwitch
{
left = 20,
top = 153,
style = “radio”,
id = “RadioButton2”,
width = 26,
height = 26,
onPress = onSwitchPress,
sheet = checkboxSheet,
frameOff = 1,
frameOn = 2
}
radioGroup:insert( radioButton2 )
sceneGroup:insert( radioButton2 )
local radioButton3 = widget.newSwitch
{
left = 20,
top = 214,
style = “radio”,
id = “RadioButton2”,
width = 26,
height = 26,
onPress = onSwitchPress,
sheet = checkboxSheet,
frameOff = 1,
frameOn = 2
}
radioGroup:insert( radioButton3 )
sceneGroup:insert( radioButton3 )
local radioButton4 = widget.newSwitch
{
left = 20,
top = 275,
style = “radio”,
id = “RadioButton2”,
width = 26,
height = 26,
onPress = onSwitchPress,
sheet = checkboxSheet,
frameOff = 1,
frameOn = 2
}
radioGroup:insert( radioButton4 )
sceneGroup:insert( radioButton4 )
local radioButton5 = widget.newSwitch
{
left = 20,
top = 336,
style = “radio”,
id = “RadioButton2”,
width = 26,
height = 26,
onPress = onSwitchPress,
sheet = checkboxSheet,
frameOff = 1,
frameOn = 2
}
radioGroup:insert( radioButton5 )
sceneGroup:insert( radioButton5 )
local function OnbtnNext( event )
if event.phase == “ended” then
local radioOn = false
if radioButton1.isOn == true then
myData.IRb4 = textVehicleOff.text
radioOn = true
end
if radioButton2.isOn == true then
myData.IRb4 = textVehicleOn.text
radioOn = true
end
if radioButton3.isOn == true then
myData.IRb4 = textIncidentInvolving.text
radioOn = true
end
if radioButton4.isOn == true then
myData.IRb4 = textAssaulted.text
radioOn = true
end
if radioButton5.isOn == true then
myData.IRb4 = textWorkRelated.text
radioOn = true
end
else
composer.gotoScene( “incidentReportingPg9”, { effect=“slideLeft”, time=800,} )
end
return true
end
–btnPrevious
local btnPrevious = widget.newButton
{
width = 150,
height = 40,
defaultFile = “btnPrevious.png”,
onEvent = btnPrevious
}
btnPrevious.x = 84
btnPrevious.y = 445
–btnNext
local btnNext = widget.newButton
{
width = 150,
height = 40,
defaultFile = “btnNext.png”,
onEvent = btnNext
}
btnNext.x = 235
btnNext.y = 445
–sceneGroup
sceneGroup:insert( titleHeader )
sceneGroup:insert( title )
sceneGroup:insert( textPage )
sceneGroup:insert( btnNext )
sceneGroup:insert( btnPrevious )
end
function scene:show( event )
local sceneGroup = self.view
end
function scene:hide( event )
local sceneGroup = self.view
end
function scene:destroy( event )
local sceneGroup = self.view
end
– Listener setup
scene:addEventListener( “create”, scene )
scene:addEventListener( “show”, scene )
scene:addEventListener( “hide”, scene )
scene:addEventListener( “destroy”, scene )
return scene
[/lua]
Thanks again,
Matt.