From a previous question, I have the following:
So I have implemented a resource class, now I'd like to continue extending it and add all my constants and enums (or as far as JS will allow...).
This is what I currently have:
var resources = {
// images
player : new c_resource("res/player.png"),
enemies : new c_resource("res/enemies.png"),
tilemap : new c_resource("res/tilemap.png")
};
And this is what I would like to continue to extend it to:
var resources = {
// images
player : new c_resource("res/player.png"),
enemies : new c_resource("res/enemies.png"),
tilemap : new c_resource("res/tilemap.png"),
// enums
directions : {up:0, right:1, down:2, left:3},
speeds : {slow: 1, medium: 3, fast: 5}
};
...
function enemies() {
this.dir = resources.directions.down; // initialize to down
}
When I attempt to access resources.directions.up, my JS script goes down in a flaming pile of burning code. Are enums allowed in this context, and if not, how can I properly insert them to be used outside of a normal function? I have also tried defining them as global to a similar effect.
edits: fixed the comma...that was just an error in transcribing it.
When I run it in Firefox and watch the console, I get an error that says resources is undefined.
The resources 'class' is defined at the top of my script, and function enemies() directly follows...so from what I understand it should still be in scope...