Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Introducing JavaScript Finishing the Game Control the Flow with Conditional Statements

How come the function item handler and badge handler was not called but yet the program still works ?

Control the flow conditional statement video

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! The answer is that they are called! Although, it might not be immediately obvious. Inside the update function around lines 122 and 123, you'll find these two lines:

game.physics.arcade.overlap(player, items, itemHandler);
game.physics.arcade.overlap(player, badges, badgeHandler);

This tells the program that when the player overlaps an item, call the itemHandler and when the player overlaps a badge, call the badgeHandler. You can find some more documentation on the overlap function in Phaser.js here

Hope this helps! :sparkles: