eliasku / ecx-common

ecx essentials
4 stars 5 forks source link

Using FSM #1

Open Misiur opened 8 years ago

Misiur commented 8 years ago

Hello. I have two questions about FSM:

  1. Assuming I have player ship and enemy ship, I had a shared codebase:
public function createShip():Entity
{
    var entity = world.create();
    _render.add(entity).setup(blahblah);

    return entity;
}

public function createPlayerShip():Entity
{
    var entity = createShip();
    _controls.add(entity).setup(blahblah);

    return entity;
}

public function createEnemyShip():Entity
{
    var entity = createShip();
    _ai.add(entity).setup(blahblah);

    return entity;
}

With FSM I can't do that anymore, but could if there was possibility of multiple callbacks for one state. Or is it not the state machine way?

  1. Sometimes I need to pass an argument to a state:
fsm.addState('following', function(world:World, entity:Entity) {
    _AI.create(entity).setup(target);
}, function(world:World, entity:Entity) {
    _AI.destroy(entity);
});

How should I go about that? Adding AI component manually works, but, well, I'd like to just use fsm.setState('following', a, list, of parameters); or something like that

eliasku commented 8 years ago

Hi!

  1. This is just simple example for state machine. I was rewritten from richard lord asteroids example, I've made a mistake incuding that to the common library. Sorry.
  2. I will review your request a bit later to suggest how to make correct behaviour
Misiur commented 8 years ago

Thanks! Since I first seen Ash framework some years ago I wanted to use ECS with FSM, so I had to try it out. Don't waste your time if those things are too specific/are not that useful in other situations.