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?
or you could load a new level
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.
var ents = ig.game.entities;
var len = ents.length;
for(var i = 0;i<len;i++){
if (ents[i] != playerEntityRef) {
ents[i].kill();
}
}
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();
}
Why are you starting at -1? inGameEntities[-1] is invalid and will end up being an error.
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 »