too stupid for composer ?!

hello.

after i solve a problem with passing throught scenes in composer, (after many of days working on it) im facing the next “big thing”

i build the app for android, to test it but the game is skipping, after the secound time calling the endless.lua

(you get, there after pressing a button in menu, to endless).

today, i thougt, ok, well, letzt take a look again into the composer template and sort your code correctly - but it does not work, whatever i do and did.

my conclusion : im to stupid for composer…

the first code, bevor sorting can be find there, last post: 

http://forums.coronalabs.com/topic/49481-problem-with-removescene/

my problem now, it have issuse to call the functions.

first  i put functions for backgrounds, light, gamelogic etc. everything in the create function and marked them all as “local”, so they would be load  firstly, but called by “functionname()” when ever i like to start it.

after that, i called every function, without user interactivity (expect of mask) at scene:show “will”

in the scene:show “did” i placed all the user interactiv functions, like starting the touchable enemys, rotating by tapping etc.

Also the physic start and eventListener are included too.

everything, was/is put in a group ( i rename the sceneGroup to group and called 2 seperat groups)

well, in the function hide:scene  “will, i removed everything called by scene:show"did”

and the “did” of hide is the remove of the whole scene “endless”(selfremove)

thats my appreciation of working with composer.

thats the result of trying to understand composer…

but: if i start the simulator, it gives me an error, 

attempt to call global “showBG”

but its there! i can see it i wrote the local function, its in the scene “create” i call it in show “will” but its not executed.

i tryed to remove the “local” bevor function showBG()

that gives me an error correlate the for loop included in this function.

i tryed to set every function sorted in scene:show, hide and will and did, just as i wrote above, without calling them, but no chance, it will not works.

composer beats me!

my code:

display.setStatusBar(display.HiddenStatusBar) local composer = require( "composer" ) local scene = composer.newScene() function scene:create( event ) local group = self.view local verlaufg = display.newGroup() local group2 = display.newGroup() ---:::local things:::--- local screenW, screenH, halfW, halfH = display.contentWidth, display.contentHeight, display.contentWidth/2, display.contentHeight/2 system.activate("multitouch") \_H = display.contentHeight; \_W = display.contentWidth; local centerX = display.contentCenterX local centerY = display.contentCenterY widget = require( "widget" ) local physics = require "physics" physics.start();physics.pause() ---:::::all the functions:::--- local function showBG(event) bg = display.newImage("bg.png") bg.anchorX = 0.5 bg.anchorY = 0.5 bg.y = \_H/2 bg.x = \_W/2 group:insert(bg) for i=1,anzahlSteine do steine[i] = display.newImageRect("stein.png",100+math.random(50) ,100 + math.random(50),2000,200) steine[i].anchorX = 0.5 steine[i].anchorX = 0.5 --steine[i]:scale(rand, rand) steine[i].x = math.random((\_W-100)) steine[i].y = math.random((\_H-100)) angle = math.deg(math.atan2((centerY-steine[i].y),(centerX-steine[i].x))) steine[i].rotation = angle -90 group:insert(steine[i]) end leftbush = display.newImage("leftbush.png") leftbush.anchorY = 0 leftbush.anchorX = 0 leftbush.y = -200 leftbush.x = -65 group:insert(leftbush) rightbush = display.newImage("rightbush.png") rightbush.anchorY = 0 rightbush.anchorX = 0 rightbush.x = 935 group:insert(rightbush) topbush = display.newImage("topbush.png") topbush.anchorY = 0 topbush.anchorX = 0 topbush.y = -60 group:insert(topbush) botbush = display.newImage("botbush.png") botbush.anchorY = 0 botbush.anchorX = 0 botbush.y = 1795 group:insert(botbush) lichtkranz = display.newImage("lichtkranz.png") lichtkranz.y, lichtkranz.x, lichtkranz.anchorX, lichtkranz.anchorY = \_H/2, \_W/2, 0.5, 0.5 lichtkranz.rotation = -90 lichtkranz.alpha = 1 lichtkranz.blendMode = "add" group:insert(lichtkranz) soldat = display.newImage("soldat.png") soldat.x = \_W/2 soldat.y = \_H/2 soldat.rotation = 0 group:insert(soldat) end ---------------------:::::::::::::BG SHOW::::::::::::::::::::---------- ---------------------:::::::::::::touch:::::::::::::::::::::---------- local function touched(event) if(event.phase == "began" or event.phase == "moved") then --soldatrotation angle = math.deg(math.atan2((event.y-soldat.y),(event.x-soldat.x))) soldat.rotation = angle + 90 --lichtkreis um den soldaten wird rotiert angle = math.deg(math.atan2((event.y-lichtkranz.y),(event.x-lichtkranz.x))) lichtkranz.rotation = angle +90 end if (event.phase == "began") then bullet = display.newImage("bullet.png") bullet.x = halfW+30 bullet.y = halfH -20 physics.addBody( bullet, "dynamic", { isSensor=true, radius=20} ) bullet.name = "bullet" group:insert(bullet) -- Find out if we need to fire the bullet to the left or right local farX = screenW\*2 local slope = ((event.yStart-screenH/2)/(event.xStart-screenW/2)) local yInt = event.yStart - (slope\*event.xStart) if(event.xStart \>= screenW/2)then farX = screenW\*2 else farX = screenW-(screenW\*2) end local farY = (slope\*farX)+yInt local xfactor = farX-bullet.x local yfactor = farY-bullet.y local distance = math.sqrt((xfactor\*xfactor) + (yfactor\*yfactor)) bullet.trans = transition.to(bullet, { time=distance/bulletSpeed, y=farY, x=farX, onComplete=nil}) end end local function creategegnerZA() -- Determine the enemies starting position local startingPosition = math.random(1,4) if(startingPosition == 1) then -- Send bad guy from left side of the screen startingX = -10 startingY = math.random(0,screenH) elseif(startingPosition == 2) then -- Send bad guy from right side of the screen startingX = screenW + 10 startingY = math.random(0,screenH) elseif(startingPosition == 3) then -- Send bad guy from the top of the screen startingX = math.random(0,screenW) startingY = -10 else -- Send bad guy from the bototm of the screen startingX = math.random(0,\_H) startingY = \_H + 10 end --Start the bad guy according to starting position gegnerZA[gegnerZAZahl] = display.newImage("zombieeye.png") gegnerZA[gegnerZAZahl].x = startingX gegnerZA[gegnerZAZahl].y = startingY physics.addBody(gegnerZA[gegnerZAZahl], "dynamic", { isSensor=true, radius=90} ) gegnerZA[gegnerZAZahl].name = "gegnerZA" group:insert(gegnerZA[gegnerZAZahl]) --rotation:: angle = math.deg(math.atan2((soldat.y-gegnerZA[gegnerZAZahl].y),(soldat.x-gegnerZA[gegnerZAZahl].x))) gegnerZA[gegnerZAZahl].rotation = angle +90 -- Then move the bad guy towards the center of the screen. Once the transition is done, remove the bad guy. gegnerZA[gegnerZAZahl].trans = transition.to(gegnerZA[gegnerZAZahl], { time=gegnerZASpeed, x=halfW, y=halfH, onComplete = function (self) self.parent:remove(self); self = nil; -- Since the bad guy has reached the monkey, we will want to remove a banana display.remove(leben[anzahlLeben]) anzahlLeben = anzahlLeben - 1 gegnerZAZahl = gegnerZAZahl + 1 -- If the numbers of lives reaches 0 or less, it's game over! if(anzahlLeben \<= 0) then timer.cancel(tmr\_creategegnerZA) bg:removeEventListener("touch", touched) local txt\_gameover = display.newText("Game Over!",0,0,native.systemFont,90) txt\_gameover.x = halfW txt\_gameover.y = screenH \* 0.3 group:insert(txt\_gameover) --txt\_gameover = display.newText("Return To Menu",0,0,native.systemFont,32) -- local txt\_gameover2 = display.newImage("endlessbtn.png") local txt\_gameover2 = widget.newButton { defaultFile = "homebtn.png", label= "bla", onEvent = onGameOverTouch } txt\_gameover2.anchorX = 0.5 txt\_gameover2.anchorY = 0.5 txt\_gameover2.x = halfW txt\_gameover2.y = screenH \* 0.7 --txt\_gameover2:addEventListener("tap", onGameOverTouch) verlaufg:insert(txt\_gameover2) end end; }) gegnerZAZahl = gegnerZAZahl + 1 end function onCollision( event ) if(event.object1.name == "gegnerZA" and event.object2.name == "bullet" or event.object1.name == "bullet" and event.object2.name == "gegnerZA") then -- Update the score score = score + 1 scoreTxt.text = ""..score --winning screen if(score == -1) then timer.cancel(tmr\_creategegnerZA) bg:removeEventListener("touch", touched) local spielvorbei = widget.newButton { defaultFile = "homebtn.png", label= "endlesssssssssssss", onEvent = onGameOverTouch } spielvorbei.x = \_W/2 spielvorbei.y = \_H/2 spielvorbei.anchorX = 0.5 spielvorbei.anchorY = 0.5 group2:insert(spielvorbei) end -- Make the objects invisible event.object1.alpha = 0 event.object2.alpha = 0 -- Cancel the transitions on the object transition.cancel(event.object1.trans) transition.cancel(event.object2.trans) -- Then remove the object after 1 cycle. Never remove display objects in the middle of collision detection. local function removeObjects() display.remove(event.object1) display.remove(event.object2) end timer.performWithDelay(1, removeObjects, 1) end end -------------:::::::::::gegnerZa:::::::::--------- --------------::::::::::verlauf::::::::::-------- local function verlauf2 (event) verlauf = display.newImage("verlauf.png") verlauf.x = \_W/2 verlauf.y = \_H/2 verlauf.anchorX, verlauf.anchorY = 0.5, 0.5 verlauf.alpha = 1 local torch = graphics.newMask("alpha3.png") verlauf:setMask(torch) verlaufg:insert(verlauf) local lichtkranz2 = display.newImage("lichtkranz.png") lichtkranz2.y, lichtkranz2.x, lichtkranz2.anchorX, lichtkranz2.anchorY = \_H/2, \_W/2, 0.5, 0.5 lichtkranz2.blendMode = "add" lichtkranz2.alpha = 0.5 lichtkranz2.isVisible = false group2:insert(lichtkranz2) group2:insert(soldat) function licht (event) if (event.phase == "began") or (event.phase == "moved") then verlauf.maskY = event.y -\_H/2 verlauf.maskX = event.x - \_W/2 lichtkranz2.x = event.x lichtkranz2.y = event.y lichtkranz2.Xscale = 0.2 lichtkranz2.isVisible = true --::torcheffect 4 Mask::-- -- Stretch the flashlight as it moves further away -- from the screen's center local radius = math.sqrt( verlauf.maskX\*verlauf.maskX + verlauf.maskY\*verlauf.maskY ) local scaleDelta = radius/radiusMax verlauf.maskScaleX = 1.3 + scaleDelta verlauf.maskScaleY = 1 + 0.2 \* scaleDelta -- Rotate it appropriately about screen center local rotation = math.deg( math.atan2( verlauf.maskY, verlauf.maskX ) ) verlauf.maskRotation = rotation --::torcheffekt4 Mask::-- --::torcheffect4 lichtkranz2::--local radius = math.sqrt( verlauf.maskX\*verlauf.maskX + verlauf.maskY\*verlauf.maskY ) local scaleDelta = radius/radiusMax lichtkranz2.ScaleX = 1 + scaleDelta lichtkranz2.ScaleY = 1 + 0.2 \* scaleDelta -- Rotate it appropriately about screen center --local rotation = math.deg( math.atan2( lichtkranz2.y, lichtkranz2.x ) ) lichtkranz2.rotation = rotation -- bg:addEventListener("touch", licht) end end end local function killsscore() kills = display.newImage("kills.png") kills.anchorX = 0.5 kills.anchorY = 0.5 kills.x = \_W/2 - 30 kills.y = \_H/25 group2:insert(kills) scoreTxt = display.newText(""..score,0,0,PWChalk,80) scoreTxt.x = \_W/2 +250 scoreTxt.y = 90 scoreTxt:setTextColor(255, 255, 255) scoreTxt.alpha = 0.5 group2:insert(scoreTxt) ---:::SCORETEXT for i=1, anzahlLeben do leben[i] = display.newImage("leben1.png") leben[i].anchorX = 0.5 leben[i].anchorY = 0.5 leben[i].x = i\*\_W/10-20 leben[i].y = \_H/22 leben[i].alpha = 0.8 group2:insert(leben[i]) end end function onGameOverTouch(event) if event.phase == "began" then composer.gotoScene( "menu", "fade", 500 ) -- group = nil end end end function scene:show( event ) local group = self.view local phase = event.phase if ( phase == "will" ) then ----::::STARTE ALLE dislay objects:::--- showBG(event) verlauf2(event) licht(event) killsscore() elseif ( phase == "did" ) then ---:::sarte gameligics:::--- physics.start() touched(event) creategegnerZA() Runtime:addEventListener("touch", licht) bg:addEventListener("touch", touched) Runtime:addEventListener("collision", onCollision) tmr\_creategegnerZA = timer.performWithDelay(gegnerZASpawnSpeed, creategegnerZA, -1) end end function scene:hide( event ) local group = self.view local phase = event.phase if ( phase == "will" ) then physics.stop() display.remove(touched(event)) display.remove(creategegnerZA()) display.remove(killsscore(event)) Runtime:removeEventListener("touch", licht) bg:removeEventListener("touch", touched) Runtime:removeEventListener("collision", onCollision) tmr\_creategegnerZA = timer.cancel(gegnerZASpawnSpeed, creategegnerZA, -1) elseif ( phase == "did" ) then composer.removeScene( "endless" ) end end function scene:destroy( event ) local sceneGroup = self.view end scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) return scene

try sorting out your “ends” (rigorously consistent indentation helps!)

on casual inspection it appears that the bulk of your code is local to scene:create(), which probably isn’t intended.

so if you tried to call showBG from scene:show it would fail because showBG is out of scope, local to scene:create.

so my guess would be that the “end” for scene:create is about a hundred lines down from where it belongs

(i haven’t tried to match them up, but i see a spot where three occur at same indentation level - one of those might be it?)

thank you but nothing helps… im working just on the composermodification for this code 3 days and im student… no, i have no scool at the moment and yes i have time, much time and jes i have spend a lot of it for fixing this composer stuff.

i think im not ready jet for it, im to bad in coding to modify my code ad pass it into this template to make it works.

it is possible to work with the scee elements without using composers scene functions? i think i can call an gotoScene and remove just everything.

i thing this functions and the sorting is just confusing me

Might I suggest dropping back and spending some time looking and studying the Composer sample app (CoronaSDK/SampleCode/Interface/Composer) and going through the various tutorials and guides that we have?  Maybe start by building a much simpler game so you’re not so overwhelmed by your game code that it’s making your composer code hard to imagine.

Rob

yes, your are right rob. thats my way ill go.

Here´s one quick and dirty way to check if the global variable really is a global variable :

– put this snippet in your code after declaring the global variable:

for k, v in pairs(_G) do  – Check global vaiables 
print( "•• My global variables   " … k )
end

run the code and go to the terminal window and  search for the global variable you just declared (cmd + f on mac, ctrl + f on PC)

If you do not find it in the terminal it is -as davebollinger said: a local variable out of scope or simply  not a global variable

try sorting out your “ends” (rigorously consistent indentation helps!)

on casual inspection it appears that the bulk of your code is local to scene:create(), which probably isn’t intended.

so if you tried to call showBG from scene:show it would fail because showBG is out of scope, local to scene:create.

so my guess would be that the “end” for scene:create is about a hundred lines down from where it belongs

(i haven’t tried to match them up, but i see a spot where three occur at same indentation level - one of those might be it?)

thank you but nothing helps… im working just on the composermodification for this code 3 days and im student… no, i have no scool at the moment and yes i have time, much time and jes i have spend a lot of it for fixing this composer stuff.

i think im not ready jet for it, im to bad in coding to modify my code ad pass it into this template to make it works.

it is possible to work with the scee elements without using composers scene functions? i think i can call an gotoScene and remove just everything.

i thing this functions and the sorting is just confusing me

Might I suggest dropping back and spending some time looking and studying the Composer sample app (CoronaSDK/SampleCode/Interface/Composer) and going through the various tutorials and guides that we have?  Maybe start by building a much simpler game so you’re not so overwhelmed by your game code that it’s making your composer code hard to imagine.

Rob

yes, your are right rob. thats my way ill go.

Here´s one quick and dirty way to check if the global variable really is a global variable :

– put this snippet in your code after declaring the global variable:

for k, v in pairs(_G) do  – Check global vaiables 
print( "•• My global variables   " … k )
end

run the code and go to the terminal window and  search for the global variable you just declared (cmd + f on mac, ctrl + f on PC)

If you do not find it in the terminal it is -as davebollinger said: a local variable out of scope or simply  not a global variable