making (lame) game, and i want to check if selected square contains a monster, however my indexOf keeps returning -1. relevant code below.
intialization:
var monsters = [];
var monsterPositions = [2,8,13,15,22];
var player = { "currentPosition": 0 };
for ( var i in monsterPositions ) {
monsters[i] = new createMonster("monster",monsterPositions[i],1); }
function createMonster(name,startingPoint,level) {
this.currentPosition = startingPoint; }
function triggered with <td>
onclick:
function processClick(trigger){
console.log( trigger.id + " " + monsterPositions );
if ( monsterPositions.indexOf(trigger.id) >= 0 ){
if ( !fight( findMonster( parseInt( trigger.id ) ) ) ){
return;
}
}
if ( gameOn ) move( parseInt( trigger.id ) );
}
the page always goes straight to move()
, even when it is a monster spot, here is console.log()
results:
1 2,8,13,15,22 adventure.js (line 79)
2 2,8,13,15,22 adventure.js (line 79)
7 2,8,13,15,22 adventure.js (line 79)
8 2,8,13,15,22 adventure.js (line 79)
13 2,8,13,15,22 adventure.js (line 79)
18 2,8,13,15,22 adventure.js (line 79)
23 2,8,13,15,22 adventure.js (line 79)
22 2,8,13,15,22 adventure.js (line 79)
21 2,8,13,15,22 adventure.js (line 79)
20 2,8,13,15,22 adventure.js (line 79)
15 2,8,13,15,22 adventure.js (line 79)
(link here if above code isnt enough), and im stumped help please.(of course why else would i be here)