Timer.performWithDelay not working

I just get a blank screen when I implement this bit of code into my project:

local firstGroup = display.newGroup()  
firstGroup:insert(rect)  
firstGroup:insert(yo)  
  
local function listener(event)  
 firstGroup.y += 50  
end  
  
timer.performWithDelay(5000, listener)  

Anybody know what the deal is? [import]uid: 47235 topic_id: 18786 reply_id: 318786[/import]

Have you tried writing it as

[code]

firstGroup.y = firstGroup.y + 50

[/code] [import]uid: 10903 topic_id: 18786 reply_id: 72316[/import]

Appreciate that man. That worked! So I’m guessing in Lua, it doesn’t recogize +=, -=, *=, etc.? Are there any good references to learn the language. I’m still not sure the difference of using a function listener and a table listener and which one is better in which situation [import]uid: 47235 topic_id: 18786 reply_id: 72322[/import]

I have found that in terms of syntax it tends to be closest to Action Script 3.

Not sure how to talk about the listeners specifically, but I find that it always depends on the situation though there are usually multiple solutions.

The listeners I use most often are Runtime Enterframe listeners for moving my game objects around, a physics listener for tracking collisions and specific touch event listeners. There are probably others here that are better at answering this who have programming backgrounds. I come from a design side. [import]uid: 10903 topic_id: 18786 reply_id: 72329[/import]

Looks like you’ve already caught it, but to re-iterate, Lua doesn’t support: += or ++ or anything like that really. Also another thing to get uset to: ~= is “not equal to” rather than “!=” … I used to make that mistake a lot coming from PHP. [import]uid: 52430 topic_id: 18786 reply_id: 72347[/import]

Well you’re pretty good for a designer. I had another problem that has been giving me fits. I’ve been trying to do a page transition and I keep getting stack traceback, Runtime assertion failed errors.
Here’s the scaled down code:

local webSolutionsButton = display.newImage("websolutionsbutton.png", 5, 222)  
webSolutionsButton.name = "webSolutionsButton"  
  
webSolutionsButton:addEventListener('tap', transitionPage)  
  
function transitionPage:tap(e)  
 if(e.target.name == "webSolutionsButton") then  
 print "This test was successful"  
 else  
 print "Test was not successful"  
 end  
end  

If you or anyone can help me out, I’ll be much obliged. This was actually for a client, but since I couldn’t get it up and running in Corona, I just did it in Cocos2d. But it’s still good to learn where I went wrong. Thanks. [import]uid: 47235 topic_id: 18786 reply_id: 72359[/import]

The function needs to be defined before it’s called. Throw the add event listener below the transitionpage function. Also, your else may not fire as the eventlistener can only track the touches to the button, not touches outside of it. [import]uid: 10903 topic_id: 18786 reply_id: 72361[/import]

I appreciate the help crssmn. I moved the eventlistener below the function but I kept getting:

  
Runtime error  
 /Users/corona/Acuta/main.lua:10: attempt to index global 'transitionPage' (a nil value)  
stack traceback:  
 [C]: ?  
 /Users/corona/Acuta/main.lua:10: in main chunk  

So I just changed:

function transitionPage:tap(e)  

to:

local function transitionPage(e)  

and it worked for some reason. When I tried to do:

local function transitionPage:tap(e)  

for some reason, the app wouldn’t even launch

[import]uid: 47235 topic_id: 18786 reply_id: 72436[/import]

I would use a touch listener rather than a tap, with the touch you get access to the different phases of the touch (began, moved, ended, cancelled).

So it would be:

  
local function transitionPage(event)  
 if event.phase == "began" then  
 print("print stuff")  
 end  
end  
  
webSolutionsButton:addEventListener("touch", transitionPage)  
  

Doing it this way can give you more interactivity with your buttons. [import]uid: 10903 topic_id: 18786 reply_id: 72456[/import]

Appreciate it. I guess that would give me more control. I’ve also seen buttons done a couple of other ways as well. It’s hard to choose which one way to go. I appreciate all your help. [import]uid: 47235 topic_id: 18786 reply_id: 72535[/import]