I have a stroke calculator for my EMS app that is having an issue.
What I’m doing is using the tableview to display multiple categories of items of which the EMS tech picks one item per category. When he picks an item from the category, the other items disappear. This is working in most situations BUT if the EMS tech gets to a category near the end of the screen, it comes up with a generic runtime error message -
Runtime Error on device (Galaxy S5)
widget_tableview:lua:494: attempt to index field ‘_view’ (a nil value).
Runtime Error on Simulator
?0:attempt to index field ‘_view’ (a nil value)
stack track back:
?:in function ‘touch’
?:in function <?:937>
?:in function <?:221>
It’s a long module… but here it is:
--------------------------------------------------------------------------------- -- SCENE NAME -- Scene notes go here --------------------------------------------------------------------------------- local globals = require( "globals" ) local storyboard = require( "storyboard" ) local scene = storyboard.newScene() local widget = require( "widget" ) local ga = require("GoogleAnalytics.ga") -- Clear previous scene storyboard.removeAll() -- local forward references should go here -- local ShowingDoc = false local downPress local killListener --------------------------------------------------------------------------------- -- BEGINNING OF YOUR IMPLEMENTATION --------------------------------------------------------------------------------- -- Called when the scene's view does not exist: function scene:createScene( event ) local group = self.view ga.enterScene("NIH Stroke Scale") -- Background color local bgImage = display.newRect( 0, 0, 380, 570 ) bgImage.strokeWidth = 0 bgImage:setFillColor( 0/255, 84/255, 166/255 ) bgImage:setStrokeColor( 0/255, 84/255, 166/255 ) bgImage.x = display.contentCenterX bgImage.y = display.contentCenterY group:insert(bgImage) -- Header 360 x 50 local bgHeader = display.newRect( 0, 0, 360, 50 ) bgHeader.strokeWidth = 0 bgHeader:setFillColor( 237/255, 237/255, 237/255 ) bgHeader:setStrokeColor( 237/255, 237/255, 237/255 ) bgHeader.x = display.contentCenterX bgHeader.y = 25 group:insert(bgHeader) -- footer 360 x 50 local bgFooter = display.newRect( 0, 0, 360, 50 ) bgFooter.strokeWidth = 0 bgFooter:setFillColor( 237/255, 237/255, 237/255 ) bgFooter:setStrokeColor( 237/255, 237/255, 237/255 ) bgFooter.x = display.contentCenterX bgFooter.y = display.contentHeight - 25 group:insert(bgFooter) local topText = display.newText( "NIH Stroke Scale", 20, 0, native.systemFontBold, 16 ) topText:setFillColor( 0 ) topText.y = 25 topText.x = display.contentCenterX group:insert(topText) -- back button local backBtn = display.newImage( "back.png" ) backBtn.x = 25 backBtn.y = 25 --backBtn:addEventListener( "tap", function( event ) -- storyboard.gotoScene( "scene\_menu" ) --end ) group:insert( backBtn) -- top Phone button local imgPhone = display.newImageRect( "callmain.png",32,32 ) imgPhone.x = display.contentWidth - 25 imgPhone.y = 25 imgPhone:addEventListener( "tap", function( event ) local options = { isModal = true, effect = "fade", time = 100, params = { sampleVar = "my sample variable" } } storyboard.showOverlay( "scene\_showoverlay", options ) end ) group:insert(imgPhone) -- -- -- local navBarHeight = 50 local tabBarHeight = 50 -- data local myDataB = {} local Section1 = 0 local Section1Val = 0 local Section2 = 0 local Section1Val = 0 local Section3 = 0 local Section1Val = 0 local Section4 = 0 local Section4Val = 0 local Section5 = 0 local Section5Val = 0 local Section6 = 0 local Section6Val = 0 local Section7 = 0 local Section7Val = 0 local Section8 = 0 local Section8Val = 0 local Section9 = 0 local Section9Val = 0 local Section10 = 0 local Section10Val = 0 local Section11 = 0 local Section11Val = 0 local Section12 = 0 local Section12Val = 0 local Section13 = 0 local Section13Val = 0 local Section14 = 0 local Section14Val = 0 local Section15 = 0 local Section15Val = 0 local Section16 = 0 local Section16Val = 0 local Section17 = 0 local Section17Val = 0 local int = 1 ------------------------------ local Section1Data Section1Data = {} Section1Data = {} Section1Data[1]={} Section1Data[1].name = "Alert" Section1Data[1].value = 0 Section1Data[2]={} Section1Data[2].name = "Drowsy" Section1Data[2].value = 1 Section1Data[3]={} Section1Data[3].name = "Stuporous" Section1Data[3].value = 3 Section1Data[4]={} Section1Data[4].name = "Coma" Section1Data[4].value = 4 --------------------------------------- local Section2Data Section2Data = {} Section2Data = {} Section2Data[1]={} Section2Data[1].name = "Answer both correctly" Section2Data[1].value = 0 Section2Data[2]={} Section2Data[2].name = "Answer one correctly" Section2Data[2].value = 1 Section2Data[3]={} Section2Data[3].name = "Incorrect" Section2Data[3].value = 2 ---------------------- local Section3Data Section3Data = {} Section3Data[1]={} Section3Data[1].name = "Obeys both questions correctly" Section3Data[1].value = 0 Section3Data[2]={} Section3Data[2].name = "Obeys one question correcty" Section3Data[2].value = 1 Section3Data[3]={} Section3Data[3].name = "Both questions Incorrect" Section3Data[3].value = 2 ---------------------- local Section4Data Section4Data = {} Section4Data[1]={} Section4Data[1].name = "Normal gaze" Section4Data[1].value = 0 Section4Data[2]={} Section4Data[2].name = "Partial gaze palsy" Section4Data[2].value = 1 Section4Data[3]={} Section4Data[3].name = "Forced deviation" Section4Data[3].value = 2 ---------------------- local Section5Data Section5Data = {} Section5Data[1]={} Section5Data[1].name = "No visual loss" Section5Data[1].value = 0 Section5Data[2]={} Section5Data[2].name = "Partial hemianopia" Section5Data[2].value = 1 Section5Data[3]={} Section5Data[3].name = "Complete hemianopia" Section5Data[3].value = 2 Section5Data[4]={} Section5Data[4].name = "Bilateral hemianopia" Section5Data[4].value = 3 ---------------------- local Section6Data Section6Data = {} Section6Data[1]={} Section6Data[1].name = "Normal Facial movement" Section6Data[1].value = 0 Section6Data[2]={} Section6Data[2].name = "Minor facial palsy" Section6Data[2].value = 1 Section6Data[3]={} Section6Data[3].name = "Partial facial palsy" Section6Data[3].value = 2 Section6Data[4]={} Section6Data[4].name = "Complete facial palsy" Section6Data[4].value = 3 ---------------------- local Section7Data Section7Data = {} Section7Data[1]={} Section7Data[1].name = "Left Arm No drift" Section7Data[1].value = 0 Section7Data[2]={} Section7Data[2].name = "Left Arm Drift" Section7Data[2].value = 1 Section7Data[3]={} Section7Data[3].name = "Left Arm Can't resist gravity" Section7Data[3].value = 2 Section7Data[4]={} Section7Data[4].name = "Left Arm No effort against gravity" Section7Data[4].value = 3 Section7Data[5]={} Section7Data[5].name = "Left Arm No movement" Section7Data[5].value = 4 Section7Data[6]={} Section7Data[6].name = "Left Arm Amputation, joint fusion" Section7Data[6].value = 9 ---------------------- local Section8Data Section8Data = {} Section8Data[1]={} Section8Data[1].name = "Right Arm No drift" Section8Data[1].value = 0 Section8Data[2]={} Section8Data[2].name = "Right Arm Drift" Section8Data[2].value = 1 Section8Data[3]={} Section8Data[3].name = "Right Arm Can't resist gravity" Section8Data[3].value = 2 Section8Data[4]={} Section8Data[4].name = "Right Arm No effort against gravity" Section8Data[4].value = 3 Section8Data[5]={} Section8Data[5].name = "Right Arm No movement" Section8Data[5].value = 4 Section8Data[6]={} Section8Data[6].name = "Right Arm Amputation, joint fusion" Section8Data[6].value = 9 ---------------------- local Section9Data Section9Data = {} Section9Data[1]={} Section9Data[1].name = "Left Leg No drift" Section9Data[1].value = 0 Section9Data[2]={} Section9Data[2].name = "Left Leg Drift" Section9Data[2].value = 1 Section9Data[3]={} Section9Data[3].name = "Left Leg Can't resist gravity" Section9Data[3].value = 2 Section9Data[4]={} Section9Data[4].name = "Left Leg No effort against gravity" Section9Data[4].value = 3 Section9Data[5]={} Section9Data[5].name = "Left Leg No movement" Section9Data[5].value = 4 Section9Data[6]={} Section9Data[6].name = "Left Leg Amputation, joint fusion" Section9Data[6].value = 9 ------------------------------- local Section10Data Section10Data = {} Section10Data[1]={} Section10Data[1].name = "Right Leg No drift" Section10Data[1].value = 0 Section10Data[2]={} Section10Data[2].name = "Right Leg Drift" Section10Data[2].value = 1 Section10Data[3]={} Section10Data[3].name = "Right Leg Can't resist gravity" Section10Data[3].value = 2 Section10Data[4]={} Section10Data[4].name = "Right Leg No effort against gravity" Section10Data[4].value = 3 Section10Data[5]={} Section10Data[5].name = "Right Leg No movement" Section10Data[5].value = 4 Section10Data[6]={} Section10Data[6].name = "Right Leg Amputation, joint fusion" Section10Data[6].value = 9 ------------------------------- local Section11Data Section11Data = {} Section11Data[1]={} Section11Data[1].name = "Limb Ataxia Absent" Section11Data[1].value = 0 Section11Data[2]={} Section11Data[2].name = "Limb Ataxia Present in upper or lower" Section11Data[2].value = 1 Section11Data[3]={} Section11Data[3].name = "Limb Ataxia Present in both" Section11Data[3].value = 2 ------------------------------- local Section12Data Section12Data = {} Section12Data[1]={} Section12Data[1].name = "Sensory Normal" Section12Data[1].value = 0 Section12Data[2]={} Section12Data[2].name = "Sensory Partial Loss" Section12Data[2].value = 1 Section12Data[3]={} Section12Data[3].name = "Sensory Dense Loss" Section12Data[3].value = 2 ------------------------------- local Section13Data Section13Data = {} Section13Data[1]={} Section13Data[1].name = "No neglect" Section13Data[1].value = 0 Section13Data[2]={} Section13Data[2].name = "Partial neglect" Section13Data[2].value = 1 Section13Data[3]={} Section13Data[3].name = "Complete neglect" Section13Data[3].value = 2 ------------------------------- local Section14Data Section14Data = {} Section14Data[1]={} Section14Data[1].name = "Normal atriculation" Section14Data[1].value = 0 Section14Data[2]={} Section14Data[2].name = "Mid to moderate Dysarthia" Section14Data[2].value = 1 Section14Data[3]={} Section14Data[3].name = "Near unintelligible or worse" Section14Data[3].value = 2 ------------------------------- local Section15Data Section15Data = {} Section15Data[1]={} Section15Data[1].name = "No aphasia" Section15Data[1].value = 0 Section15Data[2]={} Section15Data[2].name = "Mild to moderate aphasia" Section15Data[2].value = 1 Section15Data[3]={} Section15Data[3].name = "Severe aphasia" Section15Data[3].value = 2 Section15Data[4]={} Section15Data[4].name = "Mute" Section15Data[4].value = 3 ------------------------------- local Section16Data Section16Data = {} Section16Data[1]={} Section16Data[1].name = "S: Same as Previous Exam" Section16Data[1].value = 0 Section16Data[2]={} Section16Data[2].name = "B: Better as Previous Exam" Section16Data[2].value = 1 Section16Data[3]={} Section16Data[3].name = "W: Worse as Previous Exam" Section16Data[3].value = 2 ------------------------------- local Section17Data Section17Data = {} Section17Data[1]={} Section17Data[1].name = "S: Same as Best Exam" Section17Data[1].value = 0 Section17Data[2]={} Section17Data[2].name = "B: Better as Best Exam" Section17Data[2].value = 1 Section17Data[3]={} Section17Data[3].name = "W: Worse as Best Exam" Section17Data[3].value = 2 -------------------------------- -- load Section 1 ------------------------------- local function loadSection1() int = 1 myDataB = {} myDataB[int]={} myDataB[int].name = "LOC Level of Consciousness" myDataB[int].isCat = true myDataB[int].value = -1 int = int + 1 -- If there is no selection then show all if Section1 == 0 then myDataB[int]={} myDataB[int].name = Section1Data[1].name myDataB[int].value = Section1Data[1].value myDataB[int].isCat = false int = int + 1 myDataB[int]={} myDataB[int].name = Section1Data[2].name myDataB[int].value = Section1Data[2].value myDataB[int].isCat = false int = int + 1 myDataB[int]={} myDataB[int].name = Section1Data[3].name myDataB[int].value = Section1Data[3].value myDataB[int].isCat = false int = int + 1 myDataB[int]={} myDataB[int].name = Section1Data[4].name myDataB[int].value = Section1Data[4].value myDataB[int].isCat = false int = int + 1 else myDataB[int]={} myDataB[int].name = Section1Data[Section1].name myDataB[int].value = Section1Data[Section1].value myDataB[int].isCat = false int = int + 1 Section1Val = Section1Data[Section1].value end end -------------------------------------------- -- Load Section 2 -------------------------------------------- local function loadSection2() myDataB[int]={} myDataB[int].name = "LOC Questions" myDataB[int].isCat = true myDataB[int].value = -1 int = int + 1 -- If there is no selection then show all if Section2 == 0 then myDataB[int]={} myDataB[int].name = Section2Data[1].name myDataB[int].value = Section2Data[1].value myDataB[int].isCat = false int = int + 1 myDataB[int]={} myDataB[int].name = Section2Data[2].name myDataB[int].value = Section2Data[2].value myDataB[int].isCat = false int = int + 1 myDataB[int]={} myDataB[int].name = Section2Data[3].name myDataB[int].value = Section2Data[3].value myDataB[int].isCat = false int = int + 1 else myDataB[int]={} myDataB[int].name = Section2Data[Section2].name myDataB[int].value = Section2Data[Section2].value myDataB[int].isCat = false int = int + 1 Section2Val = Section2Data[Section2].value end end -------------------------------------------- -- Load Section 3 -------------------------------------------- local function loadSection3() myDataB[int]={} myDataB[int].name = "LOC Commands" myDataB[int].isCat = true myDataB[int].value = -1 int = int + 1 -- If there is no selection then show all if Section3 == 0 then myDataB[int]={} myDataB[int].name = Section3Data[1].name myDataB[int].value = Section3Data[1].value myDataB[int].isCat = false int = int + 1 myDataB[int]={} myDataB[int].name = Section3Data[2].name myDataB[int].value = Section3Data[2].value myDataB[int].isCat = false int = int + 1 myDataB[int]={} myDataB[int].name = Section3Data[3].name myDataB[int].value = Section3Data[3].value myDataB[int].isCat = false int = int + 1 else myDataB[int]={} myDataB[int].name = Section3Data[Section3].name myDataB[int].value = Section3Data[Section3].value myDataB[int].isCat = false int = int + 1 Section3Val = Section3Data[Section3].value end end -------------------------------------------- -- Load Section 4 -------------------------------------------- local function loadSection4() myDataB[int]={} myDataB[int].name = "Best Gaze" myDataB[int].isCat = true myDataB[int].value = -1 int = int + 1 -- If there is no selection then show all if Section4 == 0 then myDataB[int]={} myDataB[int].name = Section4Data[1].name myDataB[int].value = Section4Data[1].value myDataB[int].isCat = false int = int + 1 myDataB[int]={} myDataB[int].name = Section4Data[2].name myDataB[int].value = Section4Data[2].value myDataB[int].isCat = false int = int + 1 myDataB[int]={} myDataB[int].name = Section4Data[3].name myDataB[int].value = Section4Data[3].value myDataB[int].isCat = false int = int + 1 else myDataB[int]={} myDataB[int].name = Section4Data[Section4].name myDataB[int].value = Section4Data[Section4].value myDataB[int].isCat = false int = int + 1 Section4Val = Section4Data[Section4].value end end -------------------------------------------- -- Load Section 5 -------------------------------------------- local function loadSection5() myDataB[int]={} myDataB[int].name = "Best Visual" myDataB[int].isCat = true myDataB[int].value = -1 int = int + 1 -- If there is no selection then show all if Section5 == 0 then myDataB[int]={} myDataB[int].name = Section5Data[1].name myDataB[int].value = Section5Data[1].value myDataB[int].isCat = false int = int + 1 myDataB[int]={} myDataB[int].name = Section5Data[2].name myDataB[int].value = Section5Data[2].value myDataB[int].isCat = false int = int + 1 myDataB[int]={} myDataB[int].name = Section5Data[3].name myDataB[int].value = Section5Data[3].value myDataB[int].isCat = false int = int + 1 myDataB[int]={} myDataB[int].name = Section5Data[4].name myDataB[int].value = Section5Data[4].value myDataB[int].isCat = false int = int + 1 else myDataB[int]={} myDataB[int].name = Section5Data[Section5].name myDataB[int].value = Section5Data[Section5].value myDataB[int].isCat = false int = int + 1 Section5Val = Section5Data[Section5].value end end -------------------------------------------- -- Load Section 6 -------------------------------------------- local function loadSection6() myDataB[int]={} myDataB[int].name = "Facial Palsy" myDataB[int].isCat = true myDataB[int].value = -1 int = int + 1 -- If there is no selection then show all if Section6 == 0 then myDataB[int]={} myDataB[int].name = Section6Data[1].name myDataB[int].value = Section6Data[1].value myDataB[int].isCat = false int = int + 1 myDataB[int]={} myDataB[int].name = Section6Data[2].name myDataB[int].value = Section6Data[2].value myDataB[int].isCat = false int = int + 1 myDataB[int]={} myDataB[int].name = Section6Data[3].name myDataB[int].value = Section6Data[3].value myDataB[int].isCat = false int = int + 1 myDataB[int]={} myDataB[int].name = Section6Data[4].name myDataB[int].value = Section6Data[4].value myDataB[int].isCat = false int = int + 1 else myDataB[int]={} myDataB[int].name = Section6Data[Section6].name myDataB[int].value = Section6Data[Section6].value myDataB[int].isCat = false int = int + 1 Section6Val = Section6Data[Section6].value end end -------------------------------------------- -- Load Section 7 -------------------------------------------- local function loadSection7() myDataB[int]={} myDataB[int].name = "Motor Arm Left" myDataB[int].isCat = true myDataB[int].value = -1 int = int + 1 -- If there is no selection then show all if Section7 == 0 then myDataB[int]={} myDataB[int].name = Section7Data[1].name myDataB[int].value = Section7Data[1].value myDataB[int].isCat = false int = int + 1 myDataB[int]={} myDataB[int].name = Section7Data[2].name myDataB[int].value = Section7Data[2].value myDataB[int].isCat = false int = int + 1 myDataB[int]={} myDataB[int].name = Section7Data[3].name myDataB[int].value = Section7Data[3].value myDataB[int].isCat = false int = int + 1 myDataB[int]={} myDataB[int].name = Section7Data[4].name myDataB[int].value = Section7Data[4].value myDataB[int].isCat = false int = int + 1 myDataB[int]={} myDataB[int].name = Section7Data[5].name myDataB[int].value = Section7Data[5].value myDataB[int].isCat = false int = int + 1 myDataB[int]={} myDataB[int].name = Section7Data[6].name myDataB[int].value = Section7Data[6].value myDataB[int].isCat = false int = int + 1 else myDataB[int]={} myDataB[int].name = Section7Data[Section7].name myDataB[int].value = Section7Data[Section7].value myDataB[int].isCat = false int = int + 1 Section7Val = Section7Data[Section7].value end end -------------------------------------------- -- Load Section 8 -------------------------------------------- local function loadSection8() myDataB[int]={} myDataB[int].name = "Motor Arm Right" myDataB[int].isCat = true myDataB[int].value = -1 int = int + 1 -- If there is no selection then show all if Section8 == 0 then myDataB[int]={} myDataB[int].name = Section8Data[1].name myDataB[int].value = Section8Data[1].value myDataB[int].isCat = false int = int + 1 myDataB[int]={} myDataB[int].name = Section8Data[2].name myDataB[int].value = Section8Data[2].value myDataB[int].isCat = false int = int + 1 myDataB[int]={} myDataB[int].name = Section8Data[3].name myDataB[int].value = Section8Data[3].value myDataB[int].isCat = false int = int + 1 myDataB[int]={} myDataB[int].name = Section8Data[4].name myDataB[int].value = Section8Data[4].value myDataB[int].isCat = false int = int + 1 myDataB[int]={} myDataB[int].name = Section8Data[5].name myDataB[int].value = Section8Data[5].value myDataB[int].isCat = false int = int + 1 myDataB[int]={} myDataB[int].name = Section8Data[6].name myDataB[int].value = Section8Data[6].value myDataB[int].isCat = false int = int + 1 else myDataB[int]={} myDataB[int].name = Section8Data[Section8].name myDataB[int].value = Section8Data[Section8].value myDataB[int].isCat = false int = int + 1 Section8Val = Section8Data[Section8].value end end -------------------------------------------- -- Load Section 9 -------------------------------------------- local function loadSection9() myDataB[int]={} myDataB[int].name = "Motor Leg Left" myDataB[int].isCat = true myDataB[int].value = -1 int = int + 1 -- If there is no selection then show all if Section9 == 0 then myDataB[int]={} myDataB[int].name = Section9Data[1].name myDataB[int].value = Section9Data[1].value myDataB[int].isCat = false int = int + 1 myDataB[int]={} myDataB[int].name = Section9Data[2].name myDataB[int].value = Section9Data[2].value myDataB[int].isCat = false int = int + 1 myDataB[int]={} myDataB[int].name = Section9Data[3].name myDataB[int].value = Section9Data[3].value myDataB[int].isCat = false int = int + 1 myDataB[int]={} myDataB[int].name = Section9Data[4].name myDataB[int].value = Section9Data[4].value myDataB[int].isCat = false int = int + 1 myDataB[int]={} myDataB[int].name = Section9Data[5].name myDataB[int].value = Section9Data[5].value myDataB[int].isCat = false int = int + 1 myDataB[int]={} myDataB[int].name = Section9Data[6].name myDataB[int].value = Section9Data[6].value myDataB[int].isCat = false int = int + 1 else myDataB[int]={} myDataB[int].name = Section9Data[Section9].name myDataB[int].value = Section9Data[Section9].value myDataB[int].isCat = false int = int + 1 Section9Val = Section9Data[Section9].value end end -------------------------------------------- -- Load Section 10 -------------------------------------------- local function loadSection10() myDataB[int]={} myDataB[int].name = "Motor Leg Right" myDataB[int].isCat = true myDataB[int].value = -1 int = int + 1 -- If there is no selection then show all if Section10 == 0 then myDataB[int]={} myDataB[int].name = Section10Data[1].name myDataB[int].value = Section10Data[1].value myDataB[int].isCat = false int = int + 1 myDataB[int]={} myDataB[int].name = Section10Data[2].name myDataB[int].value = Section10Data[2].value myDataB[int].isCat = false int = int + 1 myDataB[int]={} myDataB[int].name = Section10Data[3].name myDataB[int].value = Section10Data[3].value myDataB[int].isCat = false int = int + 1 myDataB[int]={} myDataB[int].name = Section10Data[4].name myDataB[int].value = Section10Data[4].value myDataB[int].isCat = false int = int + 1 myDataB[int]={} myDataB[int].name = Section10Data[5].name myDataB[int].value = Section10Data[5].value myDataB[int].isCat = false int = int + 1 myDataB[int]={} myDataB[int].name = Section10Data[6].name myDataB[int].value = Section10Data[6].value myDataB[int].isCat = false int = int + 1 else myDataB[int]={} myDataB[int].name = Section10Data[Section10].name myDataB[int].value = Section10Data[Section10].value myDataB[int].isCat = false int = int + 1 Section10Val = Section10Data[Section10].value end end -------------------------------------------- -- Load Section 11 -------------------------------------------- local function loadSection11() myDataB[int]={} myDataB[int].name = "Limb Ataxia" myDataB[int].isCat = true myDataB[int].value = -1 int = int + 1 -- If there is no selection then show all if Section11 == 0 then myDataB[int]={} myDataB[int].name = Section11Data[1].name myDataB[int].value = Section11Data[1].value myDataB[int].isCat = false int = int + 1 myDataB[int]={} myDataB[int].name = Section11Data[2].name myDataB[int].value = Section11Data[2].value myDataB[int].isCat = false int = int + 1 myDataB[int]={} myDataB[int].name = Section11Data[3].name myDataB[int].value = Section11Data[3].value myDataB[int].isCat = false int = int + 1 else myDataB[int]={} myDataB[int].name = Section11Data[Section11].name myDataB[int].value = Section11Data[Section11].value myDataB[int].isCat = false int = int + 1 Section11Val = Section11Data[Section11].value end end -------------------------------------------- -- Load Section 12 -------------------------------------------- local function loadSection12() myDataB[int]={} myDataB[int].name = "Sensory" myDataB[int].isCat = true myDataB[int].value = -1 int = int + 1 -- If there is no selection then show all if Section12 == 0 then myDataB[int]={} myDataB[int].name = Section12Data[1].name myDataB[int].value = Section12Data[1].value myDataB[int].isCat = false int = int + 1 myDataB[int]={} myDataB[int].name = Section12Data[2].name myDataB[int].value = Section12Data[2].value myDataB[int].isCat = false int = int + 1 myDataB[int]={} myDataB[int].name = Section12Data[3].name myDataB[int].value = Section12Data[3].value myDataB[int].isCat = false int = int + 1 else myDataB[int]={} myDataB[int].name = Section12Data[Section12].name myDataB[int].value = Section12Data[Section12].value myDataB[int].isCat = false int = int + 1 Section12Val = Section12Data[Section12].value end end -------------------------------------------- -- Load Section 13 -------------------------------------------- local function loadSection13() myDataB[int]={} myDataB[int].name = "Neglect" myDataB[int].isCat = true myDataB[int].value = -1 int = int + 1 -- If there is no selection then show all if Section13 == 0 then myDataB[int]={} myDataB[int].name = Section13Data[1].name myDataB[int].value = Section13Data[1].value myDataB[int].isCat = false int = int + 1 myDataB[int]={} myDataB[int].name = Section13Data[2].name myDataB[int].value = Section13Data[2].value myDataB[int].isCat = false int = int + 1 myDataB[int]={} myDataB[int].name = Section13Data[3].name myDataB[int].value = Section13Data[3].value myDataB[int].isCat = false int = int + 1 else myDataB[int]={} myDataB[int].name = Section13Data[Section13].name myDataB[int].value = Section13Data[Section13].value myDataB[int].isCat = false int = int + 1 Section13Val = Section13Data[Section13].value end end -------------------------------------------- -- Load Section 14 -------------------------------------------- local function loadSection14() myDataB[int]={} myDataB[int].name = "Dysarthia" myDataB[int].isCat = true myDataB[int].value = -1 int = int + 1 -- If there is no selection then show all if Section14 == 0 then myDataB[int]={} myDataB[int].name = Section14Data[1].name myDataB[int].value = Section14Data[1].value myDataB[int].isCat = false int = int + 1 myDataB[int]={} myDataB[int].name = Section14Data[2].name myDataB[int].value = Section14Data[2].value myDataB[int].isCat = false int = int + 1 myDataB[int]={} myDataB[int].name = Section14Data[3].name myDataB[int].value = Section14Data[3].value myDataB[int].isCat = false int = int + 1 else myDataB[int]={} myDataB[int].name = Section14Data[Section14].name myDataB[int].value = Section14Data[Section14].value myDataB[int].isCat = false int = int + 1 Section14Val = Section14Data[Section14].value end end -------------------------------------------- -- Load Section 15 -------------------------------------------- local function loadSection15() myDataB[int]={} myDataB[int].name = "Best Language" myDataB[int].isCat = true myDataB[int].value = -1 int = int + 1 -- If there is no selection then show all if Section15 == 0 then myDataB[int]={} myDataB[int].name = Section15Data[1].name myDataB[int].value = Section15Data[1].value myDataB[int].isCat = false int = int + 1 myDataB[int]={} myDataB[int].name = Section15Data[2].name myDataB[int].value = Section15Data[2].value myDataB[int].isCat = false int = int + 1 myDataB[int]={} myDataB[int].name = Section15Data[3].name myDataB[int].value = Section15Data[3].value myDataB[int].isCat = false int = int + 1 myDataB[int]={} myDataB[int].name = Section15Data[4].name myDataB[int].value = Section15Data[4].value myDataB[int].isCat = false int = int + 1 else myDataB[int]={} myDataB[int].name = Section15Data[Section15].name myDataB[int].value = Section15Data[Section15].value myDataB[int].isCat = false int = int + 1 Section15Val = Section15Data[Section15].value end end -------------------------------------------- -- Load Section 16 -------------------------------------------- local function loadSection16() myDataB[int]={} myDataB[int].name = "Change from Previous Exam" myDataB[int].isCat = true myDataB[int].value = -1 int = int + 1 -- If there is no selection then show all if Section16 == 0 then myDataB[int]={} myDataB[int].name = Section16Data[1].name myDataB[int].value = Section16Data[1].value myDataB[int].isCat = false int = int + 1 myDataB[int]={} myDataB[int].name = Section16Data[2].name myDataB[int].value = Section16Data[2].value myDataB[int].isCat = false int = int + 1 myDataB[int]={} myDataB[int].name = Section16Data[3].name myDataB[int].value = Section16Data[3].value myDataB[int].isCat = false int = int + 1 else myDataB[int]={} myDataB[int].name = Section16Data[Section16].name myDataB[int].value = Section16Data[Section16].value myDataB[int].isCat = false int = int + 1 Section16Val = Section16Data[Section16].value end end -------------------------------------------- -- Load Section 17 -------------------------------------------- local function loadSection17() myDataB[int]={} myDataB[int].name = "Change from Best Exam" myDataB[int].isCat = true myDataB[int].value = -1 int = int + 1 -- If there is no selection then show all if Section17 == 0 then myDataB[int]={} myDataB[int].name = Section17Data[1].name myDataB[int].value = Section17Data[1].value myDataB[int].isCat = false int = int + 1 myDataB[int]={} myDataB[int].name = Section17Data[2].name myDataB[int].value = Section17Data[2].value myDataB[int].isCat = false int = int + 1 myDataB[int]={} myDataB[int].name = Section17Data[3].name myDataB[int].value = Section17Data[3].value myDataB[int].isCat = false int = int + 1 else myDataB[int]={} myDataB[int].name = Section17Data[Section17].name myDataB[int].value = Section17Data[Section17].value myDataB[int].isCat = false int = int + 1 Section17Val = Section17Data[Section17].value end end ---------------------------------------------------- -- Load the various sections ---------------------------------------------------- local function loadSections() -- Load Section 1 loadSection1() -- load Section 2 loadSection2() loadSection3() loadSection4() loadSection5() loadSection6() loadSection7() loadSection8() loadSection9() loadSection10() loadSection11() loadSection12() loadSection13() loadSection14() loadSection15() loadSection16() loadSection17() end ---------------------------------------------------------- -- Load tableview from data ---------------------------------------------------------- local myListB local i = 0 local function loadTable() for i = 1, #myDataB do if (myDataB[i].isCat == true) then myListB:insertRow{ rowHeight = 14, isCategory = true, rowColor = {1, 1, 1 }, lineColor = { 1, 1, 1 }, params = { name = myDataB[i].name, isCat = true, value = myDataB[i].value } } else myListB:insertRow{ rowHeight = 55, isCategory = false, rowColor = {0/255, 82/255, 154/255 }, lineColor = { 0/255, 82/255, 154/255 }, params = { name = myDataB[i].name, isCat = false, value = myDataB[i].value } } end end end local springStart = 0 local needToReload = false -------------------------------------------------------------------------- -- ------------------------------------------------------------------------ -- -- ------------------------------------------------------------------------ -------------------------------------------------------------------------- local function scrollListenerB( event ) local buffer = 50 local phase = event.phase local row = event.target local params = event.target.params if event.phase == "began" and not row.selected then startXpos = event.x startYpos = event.y row.selected = true elseif phase == "ended" or phase == "moved" then row.selected = false if phase == "ended" and event.y \< startYpos + buffer and event.y \> startYpos - buffer and event.x \< startXpos + buffer and event.x \> startXpos - buffer then if params == nil then print("category") else -- -- Cycle through the sections and see if we have a match -- -- Section 1 for i = 1, #Section1Data do -- they picked something in section 1 if (params.name == Section1Data[i].name) then -- Did they already pick something if Section1 == i then Section1 = 0 Section1Val = 0 else Section1 = i end end end -- Section 2 for i = 1, #Section2Data do -- they picked something in section 1 if (params.name == Section2Data[i].name) then -- Did they already pick something if Section2 == i then Section2 = 0 Section2Val = 0 else Section2 = i end end end -- Section 3 for i = 1, #Section3Data do -- they picked something in section 1 if (params.name == Section3Data[i].name) then -- Did they already pick something if Section3 == i then Section3 = 0 Section3Val = 0 else Section3 = i end end end -- Section 4 for i = 1, #Section4Data do -- they picked something in section 1 if (params.name == Section4Data[i].name) then -- Did they already pick something if Section4 == i then Section4 = 0 Section4Val = 0 else Section4 = i end end end -- Section 5 for i = 1, #Section5Data do -- they picked something in section 1 if (params.name == Section5Data[i].name) then -- Did they already pick something if Section5 == i then Section5 = 0 Section5Val = 0 else Section5 = i end end end -- Section 6 for i = 1, #Section6Data do -- they picked something in section 1 if (params.name == Section6Data[i].name) then -- Did they already pick something if Section6 == i then Section6 = 0 Section6Val = 0 else Section6 = i end end end -- Section 7 for i = 1, #Section7Data do -- they picked something in section 1 if (params.name == Section7Data[i].name) then -- Did they already pick something if Section7 == i then Section7 = 0 Section7Val = 0 else Section7 = i end end end -- Section 8 for i = 1, #Section8Data do -- they picked something in section 1 if (params.name == Section8Data[i].name) then -- Did they already pick something if Section8 == i then Section8 = 0 Section8Val = 0 else Section8 = i end end end -- Section 9 for i = 1, #Section9Data do -- they picked something in section 1 if (params.name == Section9Data[i].name) then -- Did they already pick something if Section9 == i then Section9 = 0 Section9Val = 0 else Section9 = i end end end -- Section 10 for i = 1, #Section10Data do -- they picked something in section 1 if (params.name == Section10Data[i].name) then -- Did they already pick something if Section10 == i then Section10 = 0 Section10Val = 0 else Section10 = i end end end -- Section 11 for i = 1, #Section11Data do -- they picked something in section 1 if (params.name == Section11Data[i].name) then -- Did they already pick something if Section11 == i then Section11 = 0 Section11Val = 0 else Section11 = i end end end -- Section 12 for i = 1, #Section12Data do -- they picked something in section 1 if (params.name == Section12Data[i].name) then -- Did they already pick something if Section12 == i then Section12 = 0 Section12Val = 0 else Section12 = i end end end -- Section 13 for i = 1, #Section13Data do -- they picked something in section 1 if (params.name == Section13Data[i].name) then -- Did they already pick something if Section13 == i then Section13 = 0 Section13Val = 0 else Section13 = i end end end -- Section 14 for i = 1, #Section14Data do -- they picked something in section 1 if (params.name == Section14Data[i].name) then -- Did they already pick something if Section14 == i then Section14 = 0 Section14Val = 0 else Section14 = i end end end -- Section 15 for i = 1, #Section15Data do -- they picked something in section 1 if (params.name == Section15Data[i].name) then -- Did they already pick something if Section15 == i then Section15 = 0 Section15Val = 0 else Section15 = i end end end -- Section 16 for i = 1, #Section16Data do -- they picked something in section 1 if (params.name == Section16Data[i].name) then -- Did they already pick something if Section16 == i then Section16 = 0 Section16Val = 0 else Section16 = i end end end -- Section 17 for i = 1, #Section17Data do -- they picked something in section 1 if (params.name == Section17Data[i].name) then -- Did they already pick something if Section17 == i then Section17 = 0 Section17Val = 0 else Section17 = i end end end -- now reload the table if myListB then myListB:deleteAllRows() --myListB:removeSelf() --myListB = nil --myListB = widget.newTableView { ---top = navBarHeight, --width = display.contentWidth, --height = display.contentHeight - navBarHeight - tabBarHeight, --backgroundColor = {0/255, 82/255, 154/255 }, --onRowRender = onRowRenderB, --onRowTouch = onRowTouchB, --listener = scrollListenerB --} --group:insert( myListB ) loadSections() loadTable() end end end end return true end -------------------------------------------------------------------------------------- --ON ROW TOUCH -------------------------------------------------------------------------------------- local function onRowTouchB(event) return true end -------------------------------------------------------------------------------------- --ON ROW RENDER -------------------------------------------------------------------------------------- local function onRowRenderB( event ) --Set up the localized variables to be passed via the event table local row = event.row local id = row.index local params = event.row.params local idx if ( event.row.params ) then idx = params.idx if row.isCategory == true then row.bg = display.newRect( 0, 0, display.contentWidth, 14 ) row.bg.anchorX = 0 row.bg.anchorY = 0 row.bg:setFillColor( 1,1,1) row.bg:setStrokeColor( 1,1,1) row:insert( row.bg ) row.nameCat = display.newText( params.name, 8, 0, native.systemFontBold, 12 ) row.nameCat.anchorX = 0 row.nameCat.anchorY = 0 row.nameCat:setFillColor( 0 ) row.nameCat.y = 0 row.nameCat.x = 10 row:insert( row.nameCat ) else idx = params.idx row.bg = display.newImageRect( "Hospitalcell.png", display.contentWidth, 55 ) row.bg.anchorX = 0 row.bg.anchorY = 0 row:insert( row.bg ) local displayTxt = params.name if string.len(displayTxt) \> 30 then displayTxt = string.sub(displayTxt,1,30).."..." end row.nameText = display.newText( displayTxt, 16, 0, native.systemFontBold, 14 ) row.nameText.anchorX = 0 row.nameText.anchorY = 0 row.nameText:setFillColor( 1 ) row.nameText.y = 10 row.nameText.x = 10 row:insert( row.nameText ) row.nameText2 = display.newText( "+"..params.value, 16, 0, native.systemFontBold, 10 ) row.nameText2.anchorX = 0 row.nameText2.anchorY = 0 row.nameText2:setFillColor( .7,.7,.7 ) row.nameText2.y =30 row.nameText2.x = 10 row:insert( row.nameText2 ) end end return true end myListB = widget.newTableView { top = navBarHeight, width = display.contentWidth, height = display.contentHeight - navBarHeight - tabBarHeight, backgroundColor = {0/255, 82/255, 154/255 }, onRowRender = onRowRenderB, onRowTouch = onRowTouchB, listener = scrollListenerB } loadSections() loadTable() group:insert( myListB ) group.x = display.contentCenterX group.y = display.contentCenterY local function GoBack() killListener() storyboard.gotoScene( "scene\_calculators" ) end ------------------------------------------------------ -- -- BACK BUTTON -- ------------------------------------------------------ backBtn:addEventListener( "tap", function( event ) GoBack() end ) local CalculateBtn = display.newImageRect( group, "hdrbtn.png", 80, 30) CalculateBtn.x = 55 CalculateBtn.y = display.contentHeight - 25 group:insert(CalculateBtn) local CalcText = display.newText( "Calculate", 20, 0, native.systemFontBold, 14) CalcText:setFillColor( 1 ) CalcText.x = 55 CalcText.y = display.contentHeight - 25 group:insert(CalcText) local ResetBtn = display.newImageRect( group, "hdrbtn.png", 80, 30) ResetBtn.x = display.contentWidth-55 ResetBtn.y = display.contentHeight - 25 group:insert(ResetBtn) local ResetText = display.newText( "Reset", 20, 0, native.systemFontBold, 14) ResetText:setFillColor( 1 ) ResetText.x = display.contentWidth-55 ResetText.y = display.contentHeight - 25 group:insert(ResetText) local ScoreText = display.newText( "Score: ", 20, 0, native.systemFontBold, 16) ScoreText:setFillColor( 0) ScoreText.x = display.contentCenterX- 10 ScoreText.y = display.contentHeight - 25 group:insert(ScoreText) CalculateBtn:addEventListener( "tap", function( event ) local temp = 0 temp = Section1Val + Section2Val + Section3Val+Section4Val + Section5Val + Section6Val+Section7Val + Section8Val + Section9Val+Section10Val + Section11Val + Section12Val+Section13Val + Section14Val + Section15Val+Section16Val + Section17Val if Section2Data[Section2].name == "Intubated" then ScoreText.text = "Score: "..temp.."T" else ScoreText.text = "Score: "..temp end end ) ResetBtn:addEventListener( "tap", function( event ) -- Reset Stuff ScoreText.text = "Score: " Section1 = 0 Section2 = 0 Section3 = 0 Section1Val = 0 Section2Val = 0 Section3Val = 0 myListB:deleteAllRows() loadSections() loadTable() end ) local function onBackButtonPressed(e) if (e.phase == "down" and e.keyName == "back") then --Here the key was pressed downPress = true return true else if (e.phase == "up" and e.keyName == "back" and downPress) then downPress = false GoBack() return true end end return false; end Runtime:addEventListener( "key", onBackButtonPressed ) killListener = function() print("--\>Stroke burn kill listener") Runtime:removeEventListener( "key", onBackButtonPressed ) end end -- Called BEFORE scene has moved onscreen: function scene:willEnterScene( event ) local group = self.view end -- Called immediately after scene has moved onscreen: function scene:enterScene( event ) local group = self.view end -- Called when scene is about to move offscreen: function scene:exitScene( event ) local group = self.view end -- Called AFTER scene has finished moving offscreen: function scene:didExitScene( event ) local group = self.view end -- Called prior to the removal of scene's "view" (display view) function scene:destroyScene( event ) local group = self.view end -- Called if/when overlay scene is displayed via storyboard.showOverlay() function scene:overlayBegan( event ) local group = self.view local overlay\_name = event.sceneName -- name of the overlay scene end -- Called if/when overlay scene is hidden/removed via storyboard.hideOverlay() function scene:overlayEnded( event ) local group = self.view local overlay\_name = event.sceneName -- name of the overlay scene end --------------------------------------------------------------------------------- -- END OF YOUR IMPLEMENTATION --------------------------------------------------------------------------------- -- "createScene" event is dispatched if scene's view does not exist scene:addEventListener( "createScene", scene ) -- "willEnterScene" event is dispatched before scene transition begins scene:addEventListener( "willEnterScene", scene ) -- "enterScene" event is dispatched whenever scene transition has finished scene:addEventListener( "enterScene", scene ) -- "exitScene" event is dispatched before next scene's transition begins scene:addEventListener( "exitScene", scene ) -- "didExitScene" event is dispatched after scene has finished transitioning out scene:addEventListener( "didExitScene", scene ) -- "destroyScene" event is dispatched before view is unloaded, which can be -- automatically unloaded in low memory situations, or explicitly via a call to -- storyboard.purgeScene() or storyboard.removeScene(). scene:addEventListener( "destroyScene", scene ) -- "overlayBegan" event is dispatched when an overlay scene is shown scene:addEventListener( "overlayBegan", scene ) -- "overlayEnded" event is dispatched when an overlay scene is hidden/removed scene:addEventListener( "overlayEnded", scene ) --------------------------------------------------------------------------------- return scene
Any help of suggestions would be GREATLY appreciated.