Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

dispatch/custom event listener
Started by willgomolka99 Jun 02 2013 04:22 PM

- - - - -
7 replies to this topic
event listener custom dispatch
[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

willgomolka99

[GLOBAL: userInfoPane.html]
willgomolka99
  • Enthusiast

  • 39 posts
  • Corona SDK

I have a game where when something happens, it will make dead = true...I know that changing dead to true works, but I need when dead = true for it to go to another function...

I have this but it doesnt work:

 
 
function updateGameDone()
director:changeScene( "ending", "moveFromLeft")
print("scene changing to ending")
return true    
end
 

 
 
local event = {
name = "dead",
dead == true
}
Runtime:dispatchEvent( event )
 
 
Runtime:addEventListener("dead", updateGameDone)
 

 

Thanks in advance



[TOPIC: post.html]
#2

torbenratzlaff

[GLOBAL: userInfoPane.html]
torbenratzlaff
  • Contributor

  • 404 posts
  • Corona SDK

You just have to change the order of your script I think.

 

First declare the eventListener and AFTER that dispatch the event.



[TOPIC: post.html]
#3

willgomolka99

[GLOBAL: userInfoPane.html]
willgomolka99
  • Enthusiast

  • 39 posts
  • Corona SDK

It doesnt work....My "Dead" is not in a table, could that be why? Is there another way to do it to recognize a function and not a table?



[TOPIC: post.html]
#4

vedantchaudhari

[GLOBAL: userInfoPane.html]
vedantchaudhari
  • Observer

  • 2 posts
  • Corona SDK

dead == true in your table, I'm pretty sure that it should just be dead = true :) 



[TOPIC: post.html]
#5

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 26,615 posts
  • Enterprise

Why don't you just call your function directly instead of trying to dispatch an event to it?  You can pass any parameter you like in that case.



[TOPIC: post.html]
#6

willgomolka99

[GLOBAL: userInfoPane.html]
willgomolka99
  • Enthusiast

  • 39 posts
  • Corona SDK

I tried constantly checking if the player was dead through a timer.performWithDelay that would go on forever and if the player was dead I called the function, but when I did this it called the function every millisecond after the player was dead and the scene was changing constantly every millisecond 



[TOPIC: post.html]
#7

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 26,615 posts
  • Enterprise

You don't need to check it all the time.  When you execute the code where you intend to dispatch the event, just call the function there.

 

Unless there is some reason why you need an event.



[TOPIC: post.html]
#8

willgomolka99

[GLOBAL: userInfoPane.html]
willgomolka99
  • Enthusiast

  • 39 posts
  • Corona SDK

I fixed it.. Instead I made another function that constantly looks for when dead == true, then I changed dead to false so that it wouldn't repeat the function again, and then i called my code to change the scene..Thanks for your help!




[topic_controls]
[/topic_controls]