Author Topic: Clarity on enemy (ID) usage  (Read 2098 times)

saiwong3268

  • Level 6: Milder
  • *
  • Posts: 119
    • View Profile
Clarity on enemy (ID) usage
« on: January 05, 2020, 01:32:09 PM »
Hi,

I need some clarity of using enemy (ID) commands.

I have created a custom enemy but I've place multiple instances of this custom enemy on screen.

When I use commands that reference the custom id number how is it interpreted.

For example if I have the following statement:

if enemy 6 x > 700
{
 enemy 6 = left
}

is this referencing a single instance of custom enemy 6 and its x coordinate
and will change direction of that specific instance of custom enemy 6 to move left
or will all instances of custom enemy 6 move left ?

what if the x coordinate of one instance is > 700 and another instance is not ?

I need to understand if commands impact just a single instance or all instances of custom enemy with same ID

what I feel I am seeing is that PB just selects one instance of the custom enemy and uses its
coordinates and ignores others. I would like to make checks on other instances of the custom enemy
« Last Edit: January 05, 2020, 01:44:50 PM by saiwong3268 »

CGM

  • Christian, 3D artist, former Platform Builder gamdev
  • Master Builder
  • *
  • Posts: 3836
    • View Profile
Re: Clarity on enemy (ID) usage
« Reply #1 on: January 05, 2020, 02:27:08 PM »
TingThing partially resolved this back in 5.1. Or maybe it was 5.2. This became an issue fast. PB always manipulates all instances in the view, or a little bit out of the view. The way to prevent this really needs to be added on to. You can only do this with enemies. Not projectiles, NPC's, blocks, items, etc. To manipulate a specefic instance, do not use the ID. PB will have to guess which enemy you're talking about sometimes if you do not define it properly. It usually does a good job. But if you have more than one enemy being referenced in the same command prompt close together, it's likely to be confused and not do anything to any enemy. This is not a super intelligent design for a lot of reasons. But it works for most purposes. I hope this helps!

PS:
I also suggested support for other objects, not just enemies the other day.

saiwong3268

  • Level 6: Milder
  • *
  • Posts: 119
    • View Profile
Re: Clarity on enemy (ID) usage
« Reply #2 on: January 05, 2020, 05:55:40 PM »
To manipulate a specefic instance, do not use the ID.

If I do not use the ID, how do I manipulate a specific instance. Please explain method to control ?

CGM

  • Christian, 3D artist, former Platform Builder gamdev
  • Master Builder
  • *
  • Posts: 3836
    • View Profile
Re: Clarity on enemy (ID) usage
« Reply #3 on: January 06, 2020, 04:09:28 AM »
I looked and looked and looked for the article that explains in detail about this. I couldn't even find the information on the Command Prompt page. If you use no ID for enemies, you can manipulate certain instances. We need TingThing to both expand this to not only work on enemies, but rather all other objects with ID's. Plus, TingThing also needs to update the command prompt page as well.

saiwong3268

  • Level 6: Milder
  • *
  • Posts: 119
    • View Profile
Re: Clarity on enemy (ID) usage
« Reply #4 on: January 06, 2020, 02:36:00 PM »
As a suggestion of how we could implement this.
In the workbench you have the "Invisible Blocks" section. Within this section are "command triggers".

How about we add "instance triggers". We place these "instance triggers" on-top of custom enemies
and we can associate an instance id  (not to be confused with enemy id) to that enemy.
The association is defined once at startup of the game. Any enemy/object/item passing over the
items later on will not inherit the instance id.

So we can have commands such as

enemy ID instance = fire projectile

e.g.
the command below instructs instance 2 of custom enemy 6 to fire
enemy 6 2 = fire projectile

the command below instructs all instances of custom enemy 6 to fire
enemy 6 all = fire projectile

the command below instructs any instance of custom enemy 6 to fire (to create random effect)
enemy 6 any = fire projectile

the command below instructs that if any instance of custom enemy 6 x coordinate is greater than 700, then all instances of custom enemy 6 should now move left
if enemy 6 any x > 700
{
enemy 6 all = left
}


you could also consider another way to associate an instance id through use of
create enemy [or] spawn enemy commands if you don't want that instance to appear at startup of game but later on






TingThing

  • Admin and Developer
  • Level 20: Nobom
  • *
  • Posts: 1395
  • Creator and Developer of Platform Builder
    • View Profile
    • Platform Builder Home
Re: Clarity on enemy (ID) usage
« Reply #5 on: January 06, 2020, 03:51:06 PM »
It's a weakness of the command prompt, to be sure.


There is a more-detailed explanation of how this all works here: https://theplatformbuilder.com/forums/index.php?topic=781.0

In some situations where you need to check specific enemies, it might work out to make several duplicates of a single enemy and group them together in a folder or something. That way each enemy gets its own ID.

Let me know if this doesn't clear things up for you.


« Last Edit: January 06, 2020, 03:58:12 PM by TingThing »

CGM

  • Christian, 3D artist, former Platform Builder gamdev
  • Master Builder
  • *
  • Posts: 3836
    • View Profile
Re: Clarity on enemy (ID) usage
« Reply #6 on: January 06, 2020, 04:20:39 PM »
That's the article I spent about 30 minutes looking for!

saiwong3268

  • Level 6: Milder
  • *
  • Posts: 119
    • View Profile
Re: Clarity on enemy (ID) usage
« Reply #7 on: January 06, 2020, 08:03:07 PM »
it might work out to make several duplicates of a single enemy and group them together in a folder or something. That way each enemy gets its own ID.

Let me know if this doesn't clear things up for you.

I can see that just making duplicates of the custom enemy could work, but it would lead to a lot
of duplication and code bloat.

for example if I wanted to test if any enemy reaches past an x coordinate and then change
direction of all enemies I might have to do

if enemy 1 x > 700 | enemy 2 x > 700 | enemy 3 x > 700 | enemy 4 x > 700 |
   enemy 5 x > 700 | enemy 6 x > 700 | enemy 7 x > 700 | enemy 8 x > 700 |
   enemy 9 x > 700 | enemy 10 x > 700
{
enemy 1 = left
enemy 2 = left
enemy 3 = left
enemy 4 = left
enemy 5 = left
enemy 6 = left
enemy 7 = left
enemy 8 = left
enemy 9 = left
enemy 10 = left
}

command code could be written in many places (e.g. timelines, custom enemy callbacks, area setting startup and looping), and any modification to code logic would need to be done in many
places and  some places could be mistakenly missed, leading to errors.
Also if you add or delete an enemy the same would need to be done.

so I would prefer in the future to be able to write something like

if enemy 6 any x > 700
{
enemy 6 all = left
}

CGM

  • Christian, 3D artist, former Platform Builder gamdev
  • Master Builder
  • *
  • Posts: 3836
    • View Profile
Re: Clarity on enemy (ID) usage
« Reply #8 on: January 06, 2020, 08:06:34 PM »
I only read the first few lines of that message, and I can see that the command prompt needs to have something done, and something soon, regarding this issue. I suggest TingThing make this a priority for 7.3.