attempt to call an upvalue (a table function) - composer

Please have a look at code below:

function playNow (event)
gfx.background.alpha=1
local obj=event.target
obj:removeSelf()
obj=nil
monkey()
end
textplay:addEventListener (“tap”, playNow)

function scene:create(event)
grp.main = self.view

monkey=display.newImage(grp.monkey, “monkey.png”)
monkey:scale(.72,.72)
monkey.value=1
monkey.isVisible=false
gfx.monkeyimg = monkey
grp.main:insert(grp.monkey)

end

function scene:show(event)
grp.main = self.view

if phase == “will” then

print(“Will statement”)
elseif phase==“did” then

function monkey()
gfx.monkeyimg.isVisible = true
gfx.monkeyimg.value=1
.
. --Here transitions on monkey also take place.
.
end
end

Please have a look at the code above. Where do I go wrong?
The error is as shown in the image file.
Help please?

What is line #56?  You’re trying to call a function but the variable is a table not a function.  I suspect it’s this line:
 

monkey()

Because monkey is later defined as a display object:

monkey=display.newImage(grp.monkey, “monkey.png”)

Monkey isn’t a function that you can call to do work.

Rob

Okay … I rectified this one. (Please correct me if again I did something wrong)

function playNow (event)
gfx.background.alpha=1
local obj=event.target
obj:removeSelf()
obj=nil
monkey()
end
textplay:addEventListener (“tap”, playNow)

function scene:create(event)
grp.main = self.view

monkey1 =display.newImage(grp.monkey, “monkey.png”)
monkey1 :scale(.72,.72)
monkey1.value=1
monkey1.isVisible=false
gfx.monkeyimg = monkey1
grp.main:insert(grp.monkey)
end

function scene:show(event)
grp.main = self.view

if phase == “will” then

print(“Will statement”)
elseif phase==“did” then

function monkey()
gfx.monkeyimg.isVisible = true
gfx.monkeyimg.value=1
.
. --Here transitions on monkey also take place.
.
end
end

Now when playNow function is called, it gives the following error: "Attempt to call upvalue ‘monkey’ (a nil value)"
I am unable to spot where I went wrong. Please help.

remove 
"

monkey()
end

"

in the top

 

Sorry? I did not get you?
Should I remove the monkey() function from listener function? If so, I want to access this function when listener function is active/called.

Help please

Can  you move your monkey() function to the top before you call it?

Rob

But shouldn’t the transitions and all must begin in scene:show function?
I had defined the playNow() function outside all the scene functions (means before the scene:create function)

You could call the function that starts the function in scene:show() but the function itself needs to be defined before you can use it.

Rob

Thank you soo much.
Moving monkey() to the top worked!

What is line #56?  You’re trying to call a function but the variable is a table not a function.  I suspect it’s this line:
 

monkey()

Because monkey is later defined as a display object:

monkey=display.newImage(grp.monkey, “monkey.png”)

Monkey isn’t a function that you can call to do work.

Rob

Okay … I rectified this one. (Please correct me if again I did something wrong)

function playNow (event)
gfx.background.alpha=1
local obj=event.target
obj:removeSelf()
obj=nil
monkey()
end
textplay:addEventListener (“tap”, playNow)

function scene:create(event)
grp.main = self.view

monkey1 =display.newImage(grp.monkey, “monkey.png”)
monkey1 :scale(.72,.72)
monkey1.value=1
monkey1.isVisible=false
gfx.monkeyimg = monkey1
grp.main:insert(grp.monkey)
end

function scene:show(event)
grp.main = self.view

if phase == “will” then

print(“Will statement”)
elseif phase==“did” then

function monkey()
gfx.monkeyimg.isVisible = true
gfx.monkeyimg.value=1
.
. --Here transitions on monkey also take place.
.
end
end

Now when playNow function is called, it gives the following error: "Attempt to call upvalue ‘monkey’ (a nil value)"
I am unable to spot where I went wrong. Please help.

remove 
"

monkey()
end

"

in the top

 

Sorry? I did not get you?
Should I remove the monkey() function from listener function? If so, I want to access this function when listener function is active/called.

Help please

Can  you move your monkey() function to the top before you call it?

Rob

But shouldn’t the transitions and all must begin in scene:show function?
I had defined the playNow() function outside all the scene functions (means before the scene:create function)

You could call the function that starts the function in scene:show() but the function itself needs to be defined before you can use it.

Rob

Thank you soo much.
Moving monkey() to the top worked!