Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Attempt to call method 'insert' <a nil value>
Started by nyeketsa May 10 2013 06:37 PM

- - - - -
1 reply to this topic
lua corona error storyboard widget
[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

nyeketsa

[GLOBAL: userInfoPane.html]
nyeketsa
  • Observer

  • 4 posts
  • Corona SDK

 
local storyboard = require( "storyboard" )
local widget=require("widget-v1");
local sprite = require("sprite")
local movieclip = require("movieclip")
--local movieclip=require("movieclip")
display.setStatusBar(display.HiddenStatusBar)
local _W=display.contentWidth;
local _H=display.contentHeight;
 
local scene = storyboard.newScene()
local narationGroup = display.newGroup();
-- latar game & tabel cerita --
local latar
local tabelCerita
local navigationBtn
local down = false
-- aset cerita ---
local kupu
local kupuSheet
local kupuSet
local kura
local kuraSheet
local kuraSet
local rusa
local rusaSheet
local rusaSet
local kelinci
local kelinciSheet
local kelinciSet
local arrowSprite
local arrow
local arrowSheet
local arrowSpriteSet
---------------------
local soundKupu = audio.loadSound ( "magic-chime-01.mp3" )
local tapKupu
local soundKelinci = audio.loadSound ( "haha.mp3" )
local tapKelinci
local tapKura
local soundkura = audio.loadSound ( "mmm.mp3" )
local function listener(event)
    if event.target.name=="kelinci" and event.phase=="began" then
        transition.to(arrow, { time = 1000, alpha = 0 })
        tapKelinci = audio.play(soundKelinci)
        kelinci:prepare("Kelincijalan")    
        kelinci:play()
    end
    if event.target.name=="kura" and event.phase=="began" then
        transition.to(arrow, { time = 1000, alpha = 0 })
        tapKura = audio.play(soundkura)
        kura:prepare("kuraGerak")
        kura:play()
    
    end
    if event.target.name=="kupu" and event.phase=="began" then
        transition.to ( kupu, {time = 3000,x = math.random (100,1024), y = math.random(40,400)} )
        tapKupu = audio.play(soundKupu)
        kupu:prepare("kupuGerak")
        kupu:play()
    end
    if event.target.name=="rusa" and event.phase=="began" then
        rusa:prepare("rusaGerak")
        rusa:play()
    end
     if event.target.name == "navigationBtn" and event.phase == "began" then
        if down == false then
            transition.to(narationGroup, { time = 1500, y = 0 })
            navigationBtn:nextFrame()
            down = true
        else
            transition.to(narationGroup, { time = 1500, y = (0 - narationGroup.height / 2) - 15 })
            navigationBtn:previousFrame()
            down = false
        end
    end
end
 
local function Tombolprev(event)
    if event.phase == "release" then
 
        storyboard.gotoScene( "menu", "fade", 800  )
        return true
    end
end
 
local function tombolnext(event)
    if event.phase == "release" then
        storyboard.gotoScene("halaman1-2","fade",800)
        return true
    end
end
 
 
 
function scene:createScene( event )
    local scene1CreateGroup = self.view
   
    latar = display.newImage ("latarHal1.png");
    scene1CreateGroup:insert(latar);
    rusaSheet = sprite.newSpriteSheet ( "sprite-rusa.png",   395, 377 )
    rusaSet = sprite.newSpriteSet ( rusaSheet, 1, 4 )
    sprite.add ( rusaSet, "rusaGerak", 1, 4, 1000, -1 )
    rusa = sprite.newSprite(rusaSet)
    rusa.x = 750;
    rusa.y = 400;
    rusa.name = "rusa"
    scene1CreateGroup:insert(rusa)
  kayu = display.newImage ("kayu.png");
    kayu.x = 690;
    kayu.y = 550;
     scene1CreateGroup:insert(kayu);
    
    
    rumput = display.newImage ("rumput.png")
    rumput.x = 950;
    rumput.y = 540;
     scene1CreateGroup:insert(rumput);
 
    kelinciSheet = sprite.newSpriteSheet ( "spritekelinci.png",   159, 239 )
    kelinciSet = sprite.newSpriteSet ( kelinciSheet, 1, 6 )
    sprite.add(kelinciSet,"Kelincijalan",1,6,1000,-1)
    kelinci = sprite.newSprite(kelinciSet)
    kelinci.x = 150;
    kelinci.y = 430;
    kelinci.name = "kelinci"
        --kelinci:prepare("KelinciJalan")
        --kelinci:play()
    scene1CreateGroup:insert(kelinci);
        -----------------------------------
        
    kuraSheet = sprite.newSpriteSheet ("sprite-kura.png",165,222)
    kuraSet = sprite.newSpriteSet ( kuraSheet, 1, 8 )
    sprite.add(kuraSet,"kuraGerak",1,8,1000,-1)
    kura = sprite.newSprite(kuraSet)
    kura.x = 350;
    kura.y = 460;
    kura.name = "kura"
        --kura:prepare("kuraGerak")
        --kura:play()
    scene1CreateGroup:insert(kura);
        -------------------------------------
        --local kupu = display.newImage ("kupu.png");
    kupuSheet = sprite.newSpriteSheet ( "sprite-kupu.png",   110, 104 )
    kupuSet = sprite.newSpriteSet ( kupuSheet, 1, 4 )
    sprite.add ( kupuSet, "kupuGerak", 1, 4, 1000, 0 )
    kupu = sprite.newSprite(kupuSet)
    kupu.x = 150;
    kupu.y = 200;
    kupu.name = "kupu"
        --kupu:prepare("kupuGerak")
        --kupu:play()
    
    scene1CreateGroup:insert(kupu);
    
    arrowSheet = sprite.newSpriteSheet("arrowSprites.png", 85, 141)
    arrowSpriteSet = sprite.newSpriteSet(arrowSheet, 1, 12)
    sprite.add(arrowSpriteSet, "ARAH", 1, 12, 600, 0)
    arrow = sprite.newSprite(arrowSpriteSet)
    arrow.x = 357
    arrow.y = 300
    arrow.name = "arah"
    scene1CreateGroup:insert(arrow);
        -------------------------------------------------
    --tabBar = display.newImage ("tabBar.png");
    --tabBar.y = 550;
    --scene1CreateGroup:insert(tabBar);
    
    tabelCerita = display.newImage( "kotakCerita1.png" );
    --tabelCerita.y = 90;
    narationGroup:insert(tabelCerita);
    navigationBtn = movieclip.newAnim{ "down.png", "up.png" }
    navigationBtn.x = 20;
    navigationBtn.y = tabelCerita.height - 30;
    navigationBtn.name = "navigationBtn"
    navigationBtn:addEventListener("touch", listener)
    narationGroup:insert(navigationBtn);
    narationGroup.x = 150
    narationGroup.y = (0- narationGroup.height/2 ) - 15
    scene1CreateGroup:insert(narationGroup);
 
end
 
function scene:enterScene( event )
    --print("enter")
    local scene1EnterGroup = self.view
    storyboard.purgeScene( "menu" )
    kelinci:addEventListener( "touch", listener )
    scene1EnterGroup:insert(kelinci)
    kupu:addEventListener( "touch", listener )
    scene1EnterGroup:insert(kupu)
    kura:addEventListener( "touch", listener )
    scene1EnterGroup:insert(kura)
    rusa:addEventListener( "touch", listener )
   -- scene1EnterGroup:insert(rusa)
 arrow:prepare("ARAH")
    arrow:play()
    scene1EnterGroup:insert(arrow)
 
    tomPrev = widget.newButton{
            default = "sample4.png",
            over = "sample44.png",
        onRelease = Tombolprev;
        }
    tomPrev.y = 300;
    tomPrev.x = 40;
scene1EnterGroup:insert(tomPrev)
    tomNext = widget.newButton {
        default = "sample3.png",
        over = "sample33.png",
        onRelease = tombolnext;
        } 
    tomNext.x = 982;
    tomNext.y = 300;
    scene1EnterGroup:insert(tomNext)
    
end
 
function scene:exitScene( event )
    --print("exit");
    local group = self.view
    display.remove(widget);
    kupu:removeEventListener( "touch", kupu )
    kelinci:removeEventListener( "touch", kelinci )
    kura:removeEventListener( "touch", kura )
    rusa:removeEventListener( "touch", rusa)
    
    narationGroup.y = (0 - narationGroup.height / 2) - 15
    navigationBtn:stopAtFrame(1)
    down = false
    navigationBtn:removeEventListener("touch", navigationBtn)
    
    kelinci:prepare("Kelincijalan")    
     kura:prepare("kuraGerak")
     kupu:prepare("kupuGerak")
     rusa:prepare("rusaGerak")
    --sius:removeEventListener( "touch", sius )
    
   
 
end
 
 
function scene:destroyScene( event )
    local group = self.view
    kupuSheet:dispose()
    kuraSheet:dispose()
    rusaSheet:dispose()
    kelinciSheet:dispose()
end
scene:addEventListener( "createScene", scene )
scene:addEventListener( "enterScene", scene )
scene:addEventListener( "exitScene", scene )
scene:addEventListener( "destroyScene", scene )
return scene
 
 

 

 

hello my name is adi, I am from Indonesia
I want to ask, I am having trouble with the code, there is an error in my code, the error message "attempt to call methods 'insert' <a nil value>, in function" insert ", page 1-1.lua: 170

 tabelCerita = display.newImage( "kotakCerita1.png" );
    --tabelCerita.y = 90;
    narationGroup:insert(tabelCerita);
    navigationBtn = movieclip.newAnim{ "down.png", "up.png" }
    navigationBtn.x = 20;
    navigationBtn.y = tabelCerita.height - 30;
    navigationBtn.name = "navigationBtn"
    navigationBtn:addEventListener("touch", listener)
    narationGroup:insert(navigationBtn);
    narationGroup.x = 150
    narationGroup.y = (0- narationGroup.height/2 ) - 15
    scene1CreateGroup:insert(narationGroup);

 
how do i solve this problem?
sorry if my english language is bad :(


[TOPIC: post.html]
#2

AlanPlantPot

[GLOBAL: userInfoPane.html]
AlanPlantPot
  • Contributor

  • 733 posts
  • Corona SDK

Well your problem is this line: narationGroup:insert(tabelCerita); It means either the narationGroup object or the tabelCerita object do not exist. First thing to do is check the spelling of the file name "kotakCerita1.png" If that is correct, I would add 2 print functions directly above the line with the error: print(narationGroup) print(tabelCerita) narationGroup:insert(tabelCerita) This will tell you which object is causing the problem.


[topic_controls]
[/topic_controls]