How can i make it when i get all the enemies i can open the switch and go to the next level

so when im playing my game i can open the switch anytime to the door to go to the next level but i want it to only can open when i kill all of the enenies
my game

2 Likes

Have the enemies always send a message to the switch, and when the switch isn’t getting the message anymore, allow it to be pressed or whatever

2 Likes

show me an example or show me how to do the code

also where do i connect it to

also use my game to show me how to do the code

So what Agent_Y said works, but it’s a really inefficient way of doing that long-term. Typically in coding, you’ll only want to do something when it’s needed, and constantly sending a message doesn’t need to be done.

Whenever an enemy DIES then you will send, so if you have 50 enemies you will only get 50 messages compared to a constant stream which is bad for performance.



This is what you’ll want to do. Each time an enemy dies it will send a message to the object that is counting how many enemies are left.

3 Likes

yes, but where do i put the message and the mailbox

The Mailbox is where it is in the image, and the Message will be sent whenever the enemy dies.

3 Likes

ok but where do i put the mailbox and the message

I already said where to put the MAILBOX.

Whatever code you use to kill the enemy, just attach the MESSAGE to it.

3 Likes

so i ahve to make a new sprite to put the Mailbox or what

The Mailbox will be in your Door object. If you don’t have anything to take you to the next level yet then you will need to make a new object

1 Like

its still doesnt work!
can you just show me the code in my game like go in my game and go to edit and do the code and post it here


This is where you put the Message

3 Likes

the switch still turns on when i dont even kill a enemy

That’s because you have a second object turning the switch on. btw the Filter needs to be equal to the number of enemies you have in the level.

3 Likes

bro it does not work just show me where and what to put eaxctly screen shot everything or just post a vid its simple

He’s going out of his way to help give a reasonable example and explanation. It wouldn’t hurt to maybe try to work the code or maybe ask where a specific part connects, etc.

Making a video might be simple for you, but some users have a life outside flowlab and might not have the time to record themselves making code, then transferring it into a YouTube link to be posted on here since the forums won’t upload videos.

2 Likes

ok but can u tell me where or how to connected because im new to flowlab im just trying to make game and some codes are difficult

2 Likes

The type of code you’re creating is very simple, but you’re overcomplicating it. You need to stop thinking of it as code and instead how to get from point A to B.

You want to open a door when all enemies have died. This is your point B.
How do you move from point A (all enemies alive and the door being locked) to point B?

  1. You need a switch to make the door locked or open, you already have this.
  2. That switch should NOT turn on unless all enemies have died. For some reason you have an object next to the player at the start turn this on, why is that there?
  3. Each time an enemy dies, send a message to the door. This is very simple, Death → Message.
  4. Now you have all the components to reach point B.
  5. When the message is received, have a Number Increase by 1. This is going to count the number of enemies that have died so far.
  6. Put that Number into a Filter. When it equals the number of total enemies you have (you need to manually set this. There is a way to automatically do this, but I don’t want to overcomplicate things for you), then you will turn on the switch, allow the player to collide with the door and move on to the next level.

It really doesn’t get more simple than this. I could send a video but what would be the point of that? You would be copying my code but you wouldn’t understand it, and that’s a mistake a lot of people make. Having things hand fed to you at the moment might help, but in a week when you need to do something similar you won’t understand how you did it before and will need help again.

4 Likes