When all the objects are inside an area

Hi, I’ll try to explain you where I’m stuck:
In this game I’m trying to create, you have to bring all the sheeps into a fence and, if you’ll do it before time runs out, the game will end.

What am I supposed to do for this action? I need a sort of counter so when all the sheeps are in the fence I can put an action and make the game end.
I’m new with this program, just be patient :slight_smile: Thanksss

@lunaluna

Here is one possibility: Drag'n Drop - Sheep JHSv1.hype.zip (17.9 KB)

I have adapted the script from this thread for our sheep management task:

Overview:

At the bottom of the function "intersectTest" script is where the "sheep tracking" code is placed. Please see "Fig.1" at the bottom of this post.

We create an array in the "Head HTML": sheepTotal = [ ]; We will use this array to track our sheep.

Each sheep has an ID number, for example: sheep-1.

As the sheep are added to the pen they have their "pointerEvents" property set to "none" so they cannot get loose out of their confine! :wink: As each sheep is added its "name" shows up in the "sheepAlert" (ID) text box.

Every time a new sheep is added the length of the "sheepTotal" array is checked. If the length (e.g. number of sheep) equals "5" - which is the total number of our sheep - then the text 'All the Sheep are in!' shows up in the "sheepAlert" (ID) text box.

Fig.1
SheepCode

2 Likes

Thank you so much, thanks to this I’ve passed an exam that was very important to me :smile:
Your suggestion was very useful and easy to get, thank you again!!!

1 Like