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

10 years ago by Roubjon

Hey guys,

Is there a way to figure out the name of the current level that is loaded? What I mean by that, is if I call

loadLevel(LevelA3);

When I declare the loadLevel funcion as :
loadLevel: function(data) {
                    this.currentLevel = data;
                    this.parent(data);
}

Is there a way to retrieve the name "LevelA3" from ig.game.currentLevel?

When I use console.log(this.currentLevel) I get the contents of the javascript file, but not the title itself.

10 years ago by Apiheld

This is not the level name, it is just the name of the variable containing the level data. You could rename your variable and still have the same object.

I'm not sure if you can access all variable names in Impact somehow, but generally speaking, this seems to be quite error-prone.

Two solutions:

1. Make a settings object in your level and retrieve it when you load the level. There, you place a key "name" with the value. I think someone posted a solution here how to store level variables / infos / settings in some specific "void" entity.

2. Ugly, because could be error prone, too:

Call your levels by string and rewrite your loadLevel function like so:

loadLevel('LevelA3');

loadLevel: function(str) {
    this.currentLevelName = str;
    this.currentLevel = eval(str);
    this.parent(this.currentLevel);
}

Now, you can access the name via this.currentLevelName;
Eval simply unwraps the string and returns the corresponding variable.
Page 1 of 1
« first « previous next › last »