Hello I have 2 functions below. The first one works, the second gives me the error Uncaught Reference Error: Projectile is not defined. However, both files are nearly identical (besides parameters), also here is the code in my Index.html, I believe defining the 2 scripts.
<script src="js/Player.js"></script>
<script src="js/Enemy.js"></script>
Methods:
function onNewEnemy(data) {
var newEnemy = new Enemy(data.x, data.y, data.id);
enemies.push(newEnemy);
};
function onNewProjectile(data, endPos) {
var newProjectile = new Projectile(data.x, data.y, endPos.x, endPos.y, 0, 10, data.id);
newProjectile.startMove(data, endPos);
projectiles.push(newProjectile);
};
Start of both files:
var Enemy = function(startX, startY, ID, typ) {
var Projectile = function(startX, startY, endX, endY, hp, dmg, ID) {
Last note:
I am calling the onNewProjectile method from inside here:
function setGameClickHandler() {
$("#gameArea").click(function(e)
{
I am rather new to JavaScript, however this minor error seems to be more challenging than necessary. If anyone could help figure out how to solve the error it would be very appreciated, thanks.
Aucun commentaire:
Enregistrer un commentaire