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

1 decade ago by ChrisD

Hello, I'm making a game, with doors that can be opened with keys, and I would like to store what doors the player has opened. I figured as I add the door entities to the map, I could set their name, then store the name in a controller class to keep track of what doors have been opened already. But I'm not quite sure how to handle this efficiently.

Is there some kind of structure where I can do like; to add it to the list then check if the list of doors unlocked contains it in O(1) time when it loads, and if it does to kill itself instantly?


PS: Sorry, this is my first project in javascript, still learning as I go.

1 decade ago by lazer

So from what I understand you actually want to kill the open doors the next time the level loads? Or am I way off here?

IF so, why not have an array of open doors in your controller class. Every time a door is opened, you push it to the array. When the level loads you go through the entire array and .kill() every entity inside. Eg:

in Controller.js:

allOpenDoors = new Array();

When the player opens a door (for example by walking into it, in which case this can be in the player's check function):;

in main.js loadLevel, after the level has loaded:

for (var i = 0; i <; i++) {
     var door =[i];
     if (door) {

(Untested and likely irrelevant if I've misunderstood what your goal is.)

1 decade ago by ChrisD


ig.DoorController = ig.Class.extend({

	init: function(){
		this.unlockedDoors = {};

	addDoorEntityToUnlockedList: function(doorName){
		this.unlockedDoors[doorName] = true;

	isDoorInUnlockedList: function(doorName){
			return true;
			return false;


I ended up doing something similar to what you suggested. Except I have doors check as initialized if they are inside of the list, if they are, they kill themselves. Each of my doors has a unique name (basically mapname and x and y coordinates).
Page 1 of 1
« first « previous next › last »