Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by congwang0517

is this right?
var ents = ig.game.entities;
var len = ents.length;
for(var i = 0;i<len;i++){
ents[i].kill();
}

any more simple way?

1 decade ago by Arantor

What are you hoping to do?

1 decade ago by fugufish

or you could load a new level

1 decade ago by alexandre

Not sure this will work but you can try

ig.game.entities.forEach(kill);

1 decade ago by Donzo

var ents = ig.game.entities;
var len = ents.length;
for(var i = 0;i<len;i++){
ents[i].kill();
}

^^^ This code worked well for me.

How could I exclude the player entity?
I'd like to have his corpse visible over the "Game Over" entity.

1 decade ago by Graphikos

var ents = ig.game.entities;
var len = ents.length;
for(var i = 0;i<len;i++){
	if (ents[i] != playerEntityRef)  {
		ents[i].kill();
	}
}

1 decade ago by FelipeBudinich

I'm currently having a similar issue, basically I want to kill all entities that extend a base entity.

			var inGameEntities = this.getEntitiesByType( 'EntityIngame' );
			var inGameEntititesLen = inGameEntities.length;
			
			for (var i = -1; i <= inGameEntititesLen; i++){
					var ent = inGameEntities[i];
					ent.kill();
			}

But i'm getting a "Cannot call method 'kill' of undefined" error. What am I missing?

EDIT

Seems that my brain needed more coffee before I went into optimization frenzy. The following code works properly.

			var inGameEntities = this.getEntitiesByType( 'EntityIngame' );
			var inGameEntititesLen = inGameEntities.length -1;
			
			for (var i = 0; i <= inGameEntititesLen; i++){
					var ent = inGameEntities[i];
					ent.kill();
			}

1 decade ago by Graphikos

Why are you starting at -1? inGameEntities[-1] is invalid and will end up being an error.

1 decade ago by FelipeBudinich

Quote from Graphikos
Why are you starting at -1? inGameEntities[-1] is invalid and will end up being an error.


My logic was "Why should I substract from the length if I could start counting from -1 instead?"

Obviously I need more coffee :-p Thanks mate!
Page 1 of 1
« first « previous next › last »