It's just names, I know, but...

Hi everyone, I’m back here boring you with one of my usual surveys. I want to create a method in which I evaluate whether an enemy has to dematerialize (and then reappear in another location) under certain conditions. What would you call this method?
I thought about:

  • CheckIfShouldDematerialize()
  • ConsiderDematerializing()

Does anything else come to mind?

Despawn?

Sorry, I’m italian. Google translator doesn’t translate “Despawn”. What does it mean?

Ah, sorry.

Well, it starts from the word “spawn” which is a common way to name the act of coming into existence of “something”.
Early references of “spawning” point to 3d shooters where players, after dying would be “spawned” in certain locations.
However, spawning refers also to game characters, objects or anything else that, as an entity, requires to come into (or out of) visibility at some point in your game.

As such, you can “spawn” ammo every 15 minutes, you can spawn an enemy right when your player steps on something and so on…

There is a family of words associated with spawning, such as:

  • despawned (entity was removed at some point, perhaps when the player used it, moved it or killed it);
  • respawned (entity was brought into “existence” again)

As per your example, it seemed to me that the proper verb would then be “despawn”.

Hope it makes more sense now. :slight_smile:

1 Like

It sounds like teleportation to me.

  1. CheckTeleport();
  2. Teleport();

if (ShouldTeleport())
{
Teleport();
}

You could even do

if (ShouldTeleport(out Vector2 new_location))
{
Teleport(new_location);
}

This is not a direct answer but here’s my 2 cents (euro).

The reason for teleporting might be different in each situation, therefore the name should reflect the test rather than the action inside it.

So instead of:

bool ShouldTeleport()
{
    if (Scared()) return true;
    if (TimeToGo()) return true;
    ... 
    ... any other teleport conditions
    return false;

}

if (ShouldTeleport())
{
    Teleport();
}

I woiuld use use:

if (Scared())
{
   Teleport();
}

if (TimeToGo())
{
    Teleport();
}

if (SaidBeamMeUp())
{
     Teleport();
}

etc etc

So the name of the test might not have anything to do with the teleport action.

This means if you decide later in development that you won’t teleport the target when it’s time to go, then the name of the test will still be valid.

You might consider composing with SOLID principles, then you can worry more about naming the class and not the method :slight_smile:

An example…

interface IEnemyBehaviour
{
  bool Check();
  void Act();
}

class EnemyTeleportBehaviour : IEnemyBehaviour
{
  private Enemy _enemy;
  public EnemyTeleportBehaviour(Enemy enemy)
  {
    _enemy = enemy ?? throw new ArgumentNullException();
  }

  public bool Check() { /* some logic to check if _enemy should teleport */ }
  public void Act() { /* some logic to teleport _enemy */ }
}

class Enemy
{
  ...
  private List<IEnemyBehaviour> _behaviours = new List<IEnemyBehaviour>();
  protected void AddBehaviour(IEnemyBehaviour behaviour) { _behaviours.Add(behaviour); }
  ...
  void Update(GameTime gameTime)
  {
    ...
    foreach (var behaviour in _behaviour)
    {
      if (behaviour.Check())
        behaviour.Act();
    }
    ...
  }
}

class TeleportingEnemy : Enemy
{
  public TeleportingEnemy()
  {
    this.AddBehaviour(new EnemyTeleportBehaviour(this));
  }
}
1 Like

Forgive me, evidently I have not explained myself well. I am not looking for a synonym / substitute for the verb “dematerialize”. In my case the verb is suitable (among other things, the method must only dematerialize the enemy, which will eventually be brought into play at a later time when certain conditions occur). My initial question referred to the first part of the method name. This method dematerializes the enemy if 3 different conditions occur at the same time. So, as I said, I thought of names like CheckIfShouldDematerialize() or ConsiderDematerializing(). You could think of names like EvaluateIfItIsAppropriateToDematerialize() or EvaluateSomeSpecificConditionsAndIfTheyAreAllTrueThenDematerialize() (now just kidding :wink:). Also, the method itself must start the dematerialization of the enemy, so I don’t need to have 2 separate methods and say “if ShouldDematerialize() then Dematerialize()”. I want to clarify that the name of this method is not at all blocking me in the continuation of coding. I was just curious what you would call this method.
Thanks

Thank you for the detailed explanation. It may be useful in the future.

When one asks for opinions on the internets, one gets opinions on the internets :wink:

You can probably take all of the above with a grain of salt, it’s just suggestions and ideas. Good luck!!

1 Like

I think we are all talking about the same thing, just with different words :smiley:

For example:

EvaluateSomeSpecificConditionsAndIfTheyAreAllTrueThenDematerialize(); is just a synoym of
CheckTeleport();, but in shorter.

In both methods you can check whatever you want to check.

You probably have a class with some private boolean fields. Then the method could look like this:

//In unit class
private bool CheckTeleport()
{
    if ((_NearEnemy && _EnergyMax) || _TeleportPowerUp) return true;
    else return false;
}

//GameLoop override
public override void GameLoop()
{
    if (CheckTeleport()) Teleport();
    else Fight();
}

So your question in the end is around how to organize your code / classes if I understood you correctly.

It’s also common to do what @Trinith showed in his example. It leads to a so called “EntityComponentSystem”. And this to a so called “SceneGraph”.

I hope this helps you finding your way.

Good luck! :slight_smile:

I can assure you that this is not a question of form but purely of words. Part of my doubts arise from the fact that English is not my language (I use the Google translator a lot to carry on this discussion). To keep it simple, suppose you have the following method:

void CheckIfShouldDematerialize()
{
    if (Type == CreatureType.Snake) 
    {
        Rectangle rect = new Rectangle(-100, -50, 200, 70);
        rect.Offset(Position);
        if (IsOnGround && !rect.Contains(EntityManager.Explorer.Position))
        {
            if (++DematerializeDelayCounter == 10 * 60)
            {
                State = CreatureState.Dematerializing; // Here the enemy starts dematerializing
            }
        }
        else
        {
            DematerializeDelayCounter = 0;
        }
    }
}

This method is all I need, I am not asking you for alternatives at the code level. All I ask you is simply: what would you call this method? As already mentioned I thought about CheckIfShouldDematerialze() or ConsiderDematerializing(). Or it could be CheckDematerialize() or ChkDemat(), or maybe you have some ideas that I haven’t remotely thought of. However, if I am boring you, you are obviously free not to answer, I am not offended.
Thanks again.

dematerialize: despawn, vanish, disintegrate

1 Like

I’m on the same page with Dismiss. One note, I would generally drop the ‘checkIf’ and simply keep method names like this: should[verb] or is[characteristic].

Examples: ShouldDespawn, IsColliding, …

Methods starting with “should” or “is”, in my oppinion should return true or false, if you want to make a method actually do something, it’s sufficient to put the verb in: jump or climb…

Sorry, english is not my native language as well. I just tried to help you.

I just think that naming things is way easier if a project is well structured. I experienced that myself.

However, personally I wouldn’t call the method “CheckIfShouldDematerialize()” because it would confuse me. Something like “CheckTeleport()” is short and directly understandable. Or like your own example “CheckDematerialize()”. This would be also ok for me.

But I would rather use a word like “Despawn” if you are not planning to just move the unit to a different location in a short amount of time. Then it’s simply “Spawn()” and “Despawn()” as well as “CheckDespawn()” and “CheckSpawn()”.

However this is just my personal way of thinking and everyone has a different opinion on that.

I agree with you, but in this case the method does not always perform the action, but only under certain conditions. Therefore, rather than “Jump”, I would say “CheckJump” or “CheckIfShouldJump”. Anyway thanks for your opinion.

I’m just here to hear opinions other than mine, perhaps opinions that I like more than mine, so thank you.

I believe it is important to hear other opinions, and this in every area. For example, if I hadn’t opened this thread, I wouldn’t have even known about the existence of verbs like Spawn and Despawn, which are apparently used a lot in game coding.
So thank you very much everyone!

1 Like