I am trying to make it possible for when the user turns one of my first three radio buttons on it sets a value in myData being (ck1) to true which is button 1 and sets any other ck(no.) to false. Now if they are false I tried to make it work like if ck1 is false then make radiobutton1,ison to false. The reason for all this is that I have two pages of radio buttons and cannot get them to function as a whole as there are on separate scenes. If there is a simple way to link them that would be great but I cannot seem to find one. Also the method im using seems to be messing with my current code and not sure why this is. If someone could shed a little light on this matter that would be great. This is the code I’m trying to use…
SCENE1
[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( “incidentReportingPg3”, { effect=“slideRight”, time=800} )
end
function scene:create( event )
local sceneGroup = self.view
–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, -10 )
sceneGroup:insert(titleHeader)
–title
local title = display.newText( “Incident Reporting”, 0, 0, native.systemFont, 32 )
title:setFillColor( 0 ) – black
title.x = display.contentWidth * 0.5
title.y = -13
sceneGroup:insert(title)
–textPage
local textPage = display.newText(“Page 4”,
280,130, display.contentWidth -25 , display.contentHeight * 0.5, native.systemFont, 15 )
textPage:setFillColor( 0, 0, 0 )
sceneGroup:insert(textPage)
–textSererity
local textSerertiy = display.newText(“Severity of Harm or Damage Caused (1 of 2):”,
172, 155, display.contentWidth, display.contentHeight * 0.5, native.systemFont, 20 )
textSerertiy:setFillColor( 0, 0, 0 )
sceneGroup:insert( textSerertiy )
–textNoHarm
local textNoHarm = display.newText(“No Harm or Damage”,
212, 229, display.contentWidth, display.contentHeight * 0.5, native.systemFont, 13 )
textNoHarm:setFillColor( 0, 0.7, 0 )
sceneGroup:insert( textNoHarm )
–textNear
local textNear = display.newText("(Near miss)",
170, 258, display.contentWidth, display.contentHeight * 0.5, native.systemFont, 13 )
textNear:setFillColor( 0, 0, 0 )
sceneGroup:insert( textNear )
–textInsignificant
local textInsignificant = display.newText(“Insignificant”,
212, 308, display.contentWidth, display.contentHeight * 0.5, native.systemFont, 13 )
textInsignificant:setFillColor( 0, 0.7, 0 )
sceneGroup:insert( textInsignificant )
–textMinimal
local textMinimal = display.newText(“Minimal injury (no first aid needed) / no repairs required / minimal impact to services property”,
170, 338, display.contentWidth, display.contentHeight * 0.5, native.systemFont, 13 )
textMinimal:setFillColor( 0, 0, 0 )
sceneGroup:insert( textMinimal )
–textMinor
local textMinor = display.newText(“Minor”,
212, 387, display.contentWidth, display.contentHeight * 0.5, native.systemFont, 13 )
textMinor:setFillColor( 0, 0.7, 0 )
sceneGroup:insert( textMinor )
–textCut
local textCut = display.newText(“Cut / bruise / basic first aid treatment required / distress / minor impact to services, property”,
170, 419, display.contentWidth, display.contentHeight * 0.5, native.systemFont, 13 )
textCut:setFillColor( 0, 0, 0 )
sceneGroup:insert( textCut )
–textPart1
local textPart1 = display.newText("**More options are available on the next page**",
180, 480, display.contentWidth, display.contentHeight * 0.5, native.systemFont, 13 )
textPart1:setFillColor( 0, 0, 0 )
sceneGroup:insert( textPart1 )
– 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 = 101,
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 = 180,
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 = 259,
style = “radio”,
id = “RadioButton2”,
width = 26,
height = 26,
onPress = onSwitchPress,
sheet = checkboxSheet,
frameOff = 1,
frameOn = 2
}
radioGroup:insert( radioButton3 )
sceneGroup:insert( radioButton3 )
local function OnbtnNext( event )
if event.phase == “ended” then
local radioOn = false
if myData.ck7 == false
then
radioButton1.isOn = false
end
if radioButton1.isOn == true then
myData.IRb3 = textNoHarm.text
radioOn = true
--Checkboxes on?
myData.ck1 = false
myData.ck2 = false
myData.ck3 = false
myData.ck4 = false
myData.ck5 = false
myData.ck6 = false
myData.ck7 = true
myData.ck8 = false
myData.ck9 = false
myData.ck10 = false
myData.ck11 = false
myData.ck12 = false
myData.ck13 = false
myData.ck14 = false
myData.ck15 = false
myData.ck16 = false
myData.ck17 = false
myData.ck18 = false
myData.ck19 = false
myData.ck20 = false
myData.ck22 = false
myData.ck23 = false
myData.ck24 = false
myData.ck25 = false
myData.ck26 = false
myData.ck27 = false
myData.ck28 = false
myData.ck29 = false
myData.ck30 = false
myData.ck31 = false
myData.ck32 = false
myData.ck33 = false
myData.ck34 = false
myData.ck35 = false
myData.ck36 = false
myData.ck37 = false
myData.ck38 = false
myData.ck39 = false
myData.ck40 = false
myData.ck41 = false
myData.ck42 = false
myData.ck43 = false
myData.ck44 = false
myData.ck45 = false
end
if myData.ck8 == false
then
radioButton2.isOn = false
end
if radioButton2.isOn == true then
myData.IRb3 = textInsignificant.text
radioOn = true
--Checkboxes on?
myData.ck1 = false
myData.ck2 = false
myData.ck3 = false
myData.ck4 = false
myData.ck5 = false
myData.ck6 = false
myData.ck7 = false
myData.ck8 = true
myData.ck9 = false
myData.ck10 = false
myData.ck11 = false
myData.ck12 = false
myData.ck13 = false
myData.ck14 = false
myData.ck15 = false
myData.ck16 = false
myData.ck17 = false
myData.ck18 = false
myData.ck19 = false
myData.ck20 = false
myData.ck22 = false
myData.ck23 = false
myData.ck24 = false
myData.ck25 = false
myData.ck26 = false
myData.ck27 = false
myData.ck28 = false
myData.ck29 = false
myData.ck30 = false
myData.ck31 = false
myData.ck32 = false
myData.ck33 = false
myData.ck34 = false
myData.ck35 = false
myData.ck36 = false
myData.ck37 = false
myData.ck38 = false
myData.ck39 = false
myData.ck40 = false
myData.ck41 = false
myData.ck42 = false
myData.ck43 = false
myData.ck44 = false
myData.ck45 = false
end
if myData.ck9 == false
then
radioButton3.isOn = false
end
if radioButton3.isOn == true then
myData.IRb3 = textMinor.text
radioOn = true
radioOn = true
--Checkboxes on?
myData.ck1 = false
myData.ck2 = false
myData.ck3 = false
myData.ck4 = false
myData.ck5 = false
myData.ck6 = false
myData.ck7 = false
myData.ck8 = false
myData.ck9 = true
myData.ck10 = false
myData.ck11 = false
myData.ck12 = false
myData.ck13 = false
myData.ck14 = false
myData.ck15 = false
myData.ck16 = false
myData.ck17 = false
myData.ck18 = false
myData.ck19 = false
myData.ck20 = false
myData.ck22 = false
myData.ck23 = false
myData.ck24 = false
myData.ck25 = false
myData.ck26 = false
myData.ck27 = false
myData.ck28 = false
myData.ck29 = false
myData.ck30 = false
myData.ck31 = false
myData.ck32 = false
myData.ck33 = false
myData.ck34 = false
myData.ck35 = false
myData.ck36 = false
myData.ck37 = false
myData.ck38 = false
myData.ck39 = false
myData.ck40 = false
myData.ck41 = false
myData.ck42 = false
myData.ck43 = false
myData.ck44 = false
myData.ck45 = false
end
else
composer.gotoScene( “incidentReportingPg5”, { 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
sceneGroup:insert(btnPrevious)
–btnNext
local btnNext = widget.newButton
{
width = 150,
height = 40,
defaultFile = “btnNext.png”,
onEvent = OnbtnNext
}
btnNext.x = 235
btnNext.y = 445
sceneGroup:insert(btnNext)
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]
SCENE 2
[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( “incidentReportingPg4”, { effect=“slideRight”, time=800} )
end
function scene:create( event )
local sceneGroup = self.view
–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 5”,
280,130, display.contentWidth -25 , display.contentHeight * 0.5, native.systemFont, 15 )
textPage:setFillColor( 0, 0, 0 )
–textSererity
local textSerertiy = display.newText(“Severity of Harm or Damage Caused (2 of 2):”,
172, 155, display.contentWidth, display.contentHeight * 0.5, native.systemFont, 20 )
textSerertiy:setFillColor( 0, 0, 0 )
sceneGroup:insert( textSerertiy )
–textModerate
local textModerate = display.newText(“Moderate”,
212, 227, display.contentWidth, display.contentHeight * 0.5, native.systemFont, 13 )
textModerate:setFillColor( 1, 0.3, 0 )
sceneGroup:insert( textModerate )
–textFractures
local textFractures = display.newText(“Fractures / sprain / strain / laceration / ill health / distress / moderate damage to property / interruption to services”,
165, 262, display.contentWidth, display.contentHeight * 0.5, native.systemFont, 13 )
textFractures:setFillColor( 0, 0, 0 )
sceneGroup:insert( textFractures )
–textMajor
local textMajor = display.newText(“Major”,
212, 322, display.contentWidth, display.contentHeight * 0.5, native.systemFont, 13 )
textMajor:setFillColor( 1, 0.3, 0 )
sceneGroup:insert( textMajor )
–textMajorInjury
local textMajorInjury = display.newText(“Major injury / multiple injuries / long term ill health damage to property / short-term loss of services / significant effect on property”,
165, 356, display.contentWidth, display.contentHeight * 0.5, native.systemFont, 13 )
textMajorInjury:setFillColor( 0, 0, 0 )
sceneGroup:insert( textMajorInjury )
–textCatastrophic
local textCatastrophic = display.newText(“Catastrophic”,
212, 417, display.contentWidth, display.contentHeight * 0.5, native.systemFont, 13 )
textCatastrophic:setFillColor( 1, 0, 0 )
sceneGroup:insert( textCatastrophic )
–textSerious
local textSerious = display.newText(“Serious injury / permanent incapacity / loss of limb / fatality / severe damage to property / long–term loss of services”,
165, 449, display.contentWidth, display.contentHeight * 0.5, native.systemFont, 13 )
textSerious:setFillColor( 0, 0, 0 )
sceneGroup:insert( textSerious )
– 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 = 100,
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 = 195,
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 = 290,
style = “radio”,
id = “RadioButton2”,
width = 26,
height = 26,
onPress = onSwitchPress,
sheet = checkboxSheet,
frameOff = 1,
frameOn = 2
}
radioGroup:insert( radioButton3 )
sceneGroup:insert( radioButton3 )
local function OnbtnNext( event )
if event.phase == “ended” then
local radioOn = false
if myData.ck10 == false
then
radioButton1.isOn = false
end
if radioButton1.isOn == true then
myData.IRb3 = textModerate.text
radioOn = true
--Checkboxes on?
myData.ck1 = false
myData.ck2 = false
myData.ck3 = false
myData.ck4 = false
myData.ck5 = false
myData.ck6 = false
myData.ck7 = false
myData.ck8 = false
myData.ck9 = false
myData.ck10 = true
myData.ck11 = false
myData.ck12 = false
myData.ck13 = false
myData.ck14 = false
myData.ck15 = false
myData.ck16 = false
myData.ck17 = false
myData.ck18 = false
myData.ck19 = false
myData.ck20 = false
myData.ck22 = false
myData.ck23 = false
myData.ck24 = false
myData.ck25 = false
myData.ck26 = false
myData.ck27 = false
myData.ck28 = false
myData.ck29 = false
myData.ck30 = false
myData.ck31 = false
myData.ck32 = false
myData.ck33 = false
myData.ck34 = false
myData.ck35 = false
myData.ck36 = false
myData.ck37 = false
myData.ck38 = false
myData.ck39 = false
myData.ck40 = false
myData.ck41 = false
myData.ck42 = false
myData.ck43 = false
myData.ck44 = false
myData.ck45 = false
end
if myData.ck11 == false
then
radioButton2.isOn = false
end
if radioButton2.isOn == true then
myData.IRb3 = textMajor.text
radioOn = true
--Checkboxes on?
myData.ck1 = false
myData.ck2 = false
myData.ck3 = false
myData.ck4 = false
myData.ck5 = false
myData.ck6 = false
myData.ck7 = false
myData.ck8 = false
myData.ck9 = false
myData.ck10 = false
myData.ck11 = true
myData.ck12 = false
myData.ck13 = false
myData.ck14 = false
myData.ck15 = false
myData.ck16 = false
myData.ck17 = false
myData.ck18 = false
myData.ck19 = false
myData.ck20 = false
myData.ck22 = false
myData.ck23 = false
myData.ck24 = false
myData.ck25 = false
myData.ck26 = false
myData.ck27 = false
myData.ck28 = false
myData.ck29 = false
myData.ck30 = false
myData.ck31 = false
myData.ck32 = false
myData.ck33 = false
myData.ck34 = false
myData.ck35 = false
myData.ck36 = false
myData.ck37 = false
myData.ck38 = false
myData.ck39 = false
myData.ck40 = false
myData.ck41 = false
myData.ck42 = false
myData.ck43 = false
myData.ck44 = false
myData.ck45 = false
end
if myData.ck12 == false
then
radioButton3.isOn = false
end
if radioButton3.isOn == true then
myData.IRb3 = textCatastrophic.text
radioOn = true
--Checkboxes on?
myData.ck1 = false
myData.ck2 = false
myData.ck3 = false
myData.ck4 = false
myData.ck5 = false
myData.ck6 = false
myData.ck7 = false
myData.ck8 = false
myData.ck9 = false
myData.ck10 = false
myData.ck11 = false
myData.ck12 = true
myData.ck13 = false
myData.ck14 = false
myData.ck15 = false
myData.ck16 = false
myData.ck17 = false
myData.ck18 = false
myData.ck19 = false
myData.ck20 = false
myData.ck22 = false
myData.ck23 = false
myData.ck24 = false
myData.ck25 = false
myData.ck26 = false
myData.ck27 = false
myData.ck28 = false
myData.ck29 = false
myData.ck30 = false
myData.ck31 = false
myData.ck32 = false
myData.ck33 = false
myData.ck34 = false
myData.ck35 = false
myData.ck36 = false
myData.ck37 = false
myData.ck38 = false
myData.ck39 = false
myData.ck40 = false
myData.ck41 = false
myData.ck42 = false
myData.ck43 = false
myData.ck44 = false
myData.ck45 = false
end
if myData.IRb3 == “No Harm or Damage” or myData.IRb3 == “Insignificant” or myData.IRb3 == “Minor” or myData.IRb3 == “Moderate” or myData.IRb3 == “Major” or myData.IRb3 == “Catastrophic” then
composer.gotoScene( “incidentReportingPg6”, { effect=“slideLeft”, time=800,} )
else
if myData.IRb3 == “N/A” then
msg = “No input in checkbox between pages(4 & 5)”
end
local alert = native.showAlert( “Warning”, "ERROR: "…msg, { “OK” }, onComplete)
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]
Thanks again,
Matt.