Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Enter Frame function doesn't work
Started by ConveyedRex7592 Mar 17 2020 08:42 AM

8 replies to this topic
enterframe function
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

ConveyedRex7592

[GLOBAL: userInfoPane.html]
ConveyedRex7592
  • Enthusiast

  • 38 posts
  • Corona SDK

 
local function hpDetection(event)

    if hp == 0 then

      composer.gotoScene("scenes.lobby")
      physics.removeBody(zombie)
      physics.removeBody(hero)
      zombie:removeSelf()
      hero:removeSelf()
      Joystick:removeSelf()
      AttackButton:removeSelf()
      hp:removeSelf()
      map:removeSelf()

    end

  end
 
  Runtime:addEventListener("enterFrame",hpDetection)
 

 

Why that doesn't work?



[TOPIC: post.html]
#2

XeduR @Spyric

[GLOBAL: userInfoPane.html]
XeduR @Spyric
  • Corona Geek

  • 1,246 posts
  • Corona SDK

What do you mean it doesn't work?

https://forums.coronalabs.com/topic/55780-ask-a-better-question-get-a-better-answer/



[TOPIC: post.html]
#3

nick_sherman

[GLOBAL: userInfoPane.html]
nick_sherman
  • Corona Geek

  • 1,974 posts
  • Corona SDK

Call me paranoid, but I'm getting the feeling hp is never zero.



[TOPIC: post.html]
#4

XeduR @Spyric

[GLOBAL: userInfoPane.html]
XeduR @Spyric
  • Corona Geek

  • 1,246 posts
  • Corona SDK

That's probably the case, and adding a "<= 0" might fix that, but I expect that once that check is cleared, then it'll run into a runtime error the very next frame.



[TOPIC: post.html]
#5

ConveyedRex7592

[GLOBAL: userInfoPane.html]
ConveyedRex7592
  • Enthusiast

  • 38 posts
  • Corona SDK

 

I mean when hp is 0 nothing happens



[TOPIC: post.html]
#6

ConveyedRex7592

[GLOBAL: userInfoPane.html]
ConveyedRex7592
  • Enthusiast

  • 38 posts
  • Corona SDK

That's probably the case, and adding a "<= 0" might fix that, but I expect that once that check is cleared, then it'll run into a runtime error the very next frame.

 

Then I add "<= 0" I get an error



[TOPIC: post.html]
#7

XeduR @Spyric

[GLOBAL: userInfoPane.html]
XeduR @Spyric
  • Corona Geek

  • 1,246 posts
  • Corona SDK

What kind of error? Did you include the quotation marks there too, because that'd lead to an error too.

 

The easiest way to get help is to provide us with a small sample project that demonstrates your issue. Based on the code you've shared, we can only guess. It might seem like plenty, but we don't know what the error is, we don't know what problems you are facing, we don't know anything for certain when it comes to what you've shared.

Help us help you. Create a small project that demonstrates your issue so that we can help you debug it.



[TOPIC: post.html]
#8

ConveyedRex7592

[GLOBAL: userInfoPane.html]
ConveyedRex7592
  • Enthusiast

  • 38 posts
  • Corona SDK

I found a mistake! I needed to add hero.hp not hp.



[TOPIC: post.html]
#9

XeduR @Spyric

[GLOBAL: userInfoPane.html]
XeduR @Spyric
  • Corona Geek

  • 1,246 posts
  • Corona SDK

That's a perfect example of a "problem with my code" that no one else could have figured out in a million years.




[topic_controls]
[/topic_controls]

Also tagged with one or more of these keywords: enterframe, function