I had a go at following a tutuorial on how to make an alphabet soup game for corona (link) - http://mobile.tutsplus.com/tutorials/corona/corona-sdk-create-an-alphabet-soup-game/
however, I wanted to have a go at doing my own stuff with the code. It all works well until I put it into the storyboard. I’ve done the menu but i can’t get the scene 1 to work. The background image of scene 1 comes up however the letters do not.
in the code I have commented line 78 because that line comes up with an error.
-- my game -- scene1.lua local storyboard = require ( "storyboard" ) local scene = storyboard.newScene() --create scene function scene:createScene(event) local screenGroup = self.view local gameBg = display.newImage('bg.png') end function scene:enterScene(event) local group = self.view -- local L1 is the word that the player must find. local L1 = {'DOG'} local L1Map = {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 'D', 'O', 'G'}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}} local alphabet = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'} local correct = 0 local clueText = display.newText( "DOG", 0, 450, Arial, 16) clueText:setTextColor(255, 255, 255) --local clueText displays the the word the player must find. function buildSoup() for i = 1, 10 do for j = 1, 12 do local tf = display.newText('', 0, 0, 'Arial', 19) tf:setTextColor(102, 102, 102) tf.width = 320 tf.height = 480 tf.x = math.floor(-10 + (31.3 \* i)) tf.y = math.floor(-10 + (35 \* j)) -- Change 0's to Random Letters if(L1Map[j][i] == 0) then L1Map[j][i] = alphabet[math.floor(math.random() \* table.maxn(alphabet))+1] end tf.text = L1Map[j][i] tfs:insert(tf) end end -- Add Words List local wordsString = '' for i = 1, #L1 do wordsString = wordsString .. ' ' .. L1[i] end wordsList = display.newText(wordsString, 10000, 10000, 'Arial', 14) wordsList:setTextColor(238, 238, 238) currentWords = display.newText('', 10000, 10000, 'Arial', 14) currentWords:setTextColor(238, 146, 63) end function startDraw:touch(e) -- I get an error on this line: attempt to index global "start draw" \<a nil value\> if(e.phase == 'began') then initX = e.x initY = e.y elseif(e.phase == 'ended') then line = display.newLine(initX, initY, e.x, e.y) line.width = 16 line:setColor(255, 142, 42, 60) lines:insert(line) end end function hitTestObjects(obj1, obj2) local left = obj1.contentBounds.xMin \<= obj2.contentBounds.xMin and obj1.contentBounds.xMax \>= obj2.contentBounds.xMin local right = obj1.contentBounds.xMin \>= obj2.contentBounds.xMin and obj1.contentBounds.xMin \<= obj2.contentBounds.xMax local up = obj1.contentBounds.yMin \<= obj2.contentBounds.yMin and obj1.contentBounds.yMax \>= obj2.contentBounds.yMin local down = obj1.contentBounds.yMin \>= obj2.contentBounds.yMin and obj1.contentBounds.yMin \<= obj2.contentBounds.yMax return (left or right) and (up or down) end function detectLetters:touch(e) if(e.phase == 'ended') then -- Get selected letters local selectedWord = '' for i = 1, tfs.numChildren do if(hitTestObjects(lines[lines.numChildren], tfs[i])) then selectedWord = selectedWord .. tfs[i].text end end -- Check if word is on list for j = 0, 5 do if(selectedWord == L1[j]) then audio.play(bell) currentWords.text = currentWords.text .. ' ' .. selectedWord currentWords:setReferencePoint(display.TopLeftReferencePoint) currentWords.x = 5 correct = correct + 1 end end end if(correct == #L1) then alert() end end function gameListeners(action) if(action == 'add') then gameBg:addEventListener('touch', startDraw) gameBg:addEventListener('touch', detectLetters) else gameBg:removeEventListener('touch', startDraw) gameBg:removeEventListener('touch', detectLetters) end end function alert() gameListeners('rm') alert = display.newImage('alert.png') --alert:addEventListener('tap', restart) or next level! end end function scene:exitScene(event) local group = self.view end function scene:destroyScene(event) local group = self.view end scene:addEventListener( "createScene", scene ) scene:addEventListener( "enterScene", scene ) scene:addEventListener( "exitScene", scene ) scene:addEventListener( "destroyScene", scene ) return scene
thanks in advance if you can help me
