Author Topic: Picking out Specific Enemies, Items, etc., in Command Prompt.  (Read 5932 times)

TingThing

  • Admin and Developer
  • Level 20: Nobom
  • *
  • Posts: 1395
  • Creator and Developer of Platform Builder
    • View Profile
    • Platform Builder Home
Picking out Specific Enemies, Items, etc., in Command Prompt.
« on: December 22, 2018, 04:58:48 AM »
Hello everyone,


For those of you working with commands, you have probably noticed that many commands are available to modify enemies, items, blocks, projectiles, etc. When these commands, you usually need to specify an ID of whatever you are working with. For instance, if you want to destroy an enemy, you could use "Remove Enemy 5" In this example, 5 is the ID. However, commands like these will work on all enemies in view and nearby with that ID. you may not want that. How do you pick out a specific custom enemy?


There are three primary methods that you can do this in Platform Builder. We will keep using this example "Remove Enemy 5," but the same method applies for items, projectiles, blocks, and sprites as well.


Method 1: If an enemy-based command is used without an enemy ID and it is being called from an enemy, it will apply only to the enemy that called it.

This may sound a bit confusing. Allow me to explain in more detail...

Typically, commands that deal with enemies will modify every custom enemy that is visible in the view (and nearby) of the given ID. For instance, if you have 5 of the same custom enemies in the view, each with an ID of 3, and you run the command "remove enemy 5" it will remove all five of those enemies.

However, If you remove the enemy ID from your command, Platform Builder will check if this command is coming from a custom enemy. If it is, then the command will apply just to that one custom enemy. A command comes from a custom enemy if it was written in a custom enemy command prompt.

 


So if you want to remove one specific enemy with and ID of 5 (and not all of them), then you want to see if you can call the command from one of those enemy command prompts. If it is, then simply put "remove enemy" instead of "remove enemy 5." Problem solved!


If you try to do this in other command prompts, it won't work. If you try doing this in the area settings startup command (for instance), Platform Builder will have no idea which enemy it is supposed to modify. But if you do this in an enemy command prompt, there shouldn't be a problem.

This can also work in the first two projectile command prompts. If an enemy fires a projectile, and the projectile has commands for when it is fired, the commands no longer need an enemy ID. Similarly, if a custom projectile strikes a custom enemy, and the projectile has commands for when it strikes a target, you don't need the enemy ID anymore. By leaving that out, the enemy commands will apply only to the enemy that was struck.





What if you have to remove your enemy from a different command prompt? Well, you have two other methods...


Method 2: You can use "With nearest enemy 5" to find the closest enemy 5 to whatever is calling the command, and then call your enemy-based command without using an ID.


For instance:
Code: [Select]
with nearest enemy 5
remove enemy


The example above starts by finding the closest enemy with an ID of 5 to whatever is calling it. So, for instance, if this is being called from a character command prompt, Platform Builder will look for the closest enemy with an ID of 5 to the character. Then, it will destroy that enemy. Since you used "with nearest enemy" to pick out a specific enemy, you no longer need to specify an ID for enemy-based commands.


The "with nearest" command also works if you do not specify an ID. If you wrote "with nearest enemy" instead of "with nearest enemy 5," it will find the closest custom enemy, regardless of whatever the enemy's ID is.


There are three things to keep in mind when using these "with nearest" commands:
(1) This only works if the nearest enemy is within the view or closely nearby.
(2) This will only work as long as you do NOT include the enemy ID with the enemy command.
(3) This will replace the information for whatever originally called the command. So, if the command is called from a custom block, you will no longer be able to use block-based commands without specifying the block ID.


If nether of those methods work, there is one more way to do this.


Method 3: Create duplicates of a single enemy and store them all in a folder. This way you can have multiple enemies that work the same way but have their own unique ID.


If you cannot use method 1 or method 2, then you will have to just build your game so that there are no more than a single enemy with the same ID present when you call the command. It will take a little bit of time, but it can work in many situations. Now, you can call "remove enemy 5" and it will only remove that one enemy, but the other enemies with different IDs will remain.



What about Items, Blocks, Projectiles, and Sprites?
Everything above applies to items, blocks, projectiles, and sprites, too. For instance, you could write "trigger block" instead of "trigger block 3" if it is being called from a command prompt in the custom block settings. You could also write "with nearest item" in order to pick out the item that is closest.

The only think to keep in mind is that projectile-based commands still require an ID if called from "Fire Projectile" and "Strike Target" commands prompts in the projectile settings. This is because (as we have already seen) those commands apply to enemies, not projectiles. It's confusing, I know. I would have done it differently but it's something left over from previous versions of Platform Builder when the method only worked for enemies and not projectiles.

What about other commands?
We used "remove enemy" as an example because it is an enemy-based command. But there are many other enemy-based commands that would also work. For instance...
Code: [Select]
enemy x + 5
kill enemy
enemy = item 4
enemy effect = 3
enemy jump
All of those commands are examples of enemy-based commands. They normally require an enemy ID but as we just saw, the ID is not always necessary. And, of course, you have block-based commands that usually require a block ID, or item-based commands, etc.

I hope that helps!

Best,
TingThing
« Last Edit: January 20, 2020, 07:52:33 PM by TingThing »

Antikore

  • Developing Mortal Theater at day, developing depression at night.
  • Level 22: Trex
  • *
  • Posts: 2020
  • Enjoying Platform Builder from the very start
    • View Profile
    • PBuilder Resources
Re: Picking out Specific Enemies, Items, etc., in Command Prompt.
« Reply #1 on: January 29, 2020, 12:58:34 PM »
Coolo, that's a very cool guide.
Sorry because my English is not very good because I'm Spanish ;) :P

CGM

  • Christian, 3D artist, former Platform Builder gamdev
  • Master Builder
  • *
  • Posts: 3836
    • View Profile
Re: Picking out Specific Enemies, Items, etc., in Command Prompt.
« Reply #2 on: January 29, 2020, 03:03:55 PM »
Hope it helps new users down the road! You should probably put this tutorial into the manual. Not everybody looks at the forums, you know.