trying to keep this short. Using phpstorm to look over my code and got a few errors.
It says my function naming locations has a "Variable Implicitly Declared"
function towngate10() {
updateDisplay(locations[10].description);
if (!gate10) {
score = score+5;
gate10 = true;
}
playerLocation = 10;
displayScore();
document.getElementById("goNorth").disabled=true;
document.getElementById("goSouth").disabled=false;
document.getElementById("goEast").disabled=true;
document.getElementById("goWest").disabled=true;
}
Also, I just want to make sure I went about my prototypes correctly Just a sample
Global Arrays:
var locations = [10];
locations[0] = new Location(0,"Intersection","This is where you awoke.");
locations[1] = new Location(1,"Cornfield","The cornfields expand for miles.");
locations[2] = new Location(2,"Lake","A large lake that is formed by a river flowing from the East.", new Item(1,"Fish","An old rotting fish."));
locations[3] = new Location(3,"Outside Cave","Entrance to the dark cave.");
Location function:
function Location(id, name, description, item) {
this.id = id;
this.name = name;
this.description = description;
this.item = item;
this.toString = function() {
return "Location: " + this.name + " - " + this.description;
}
}
Regarding variables being implicitly declared:
if (!gate10) {
score = score+5;
gate10 = true;
}
and
playerLocation = 10;
score,gate and playerLocation are being created as 'global' variables. Phpstorm will alert you to this. Unless they are intended to be globally accessible, declare the variables with var instead. This will make the variables local only to the scope in which it's created:
if (!gate10) {
var score = score+5;
var gate10 = true;
}
and
var playerLocation = 10;
I suggest you read more about variable scoping. Global variables can leave gaps in your security if they aren't properly handled.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With