-2
\$\begingroup\$

It tells me the error is on this line: this.srcX = ShipSrcXPicker(type);

However I cannot see it? I am returning the values from these methods that are being called? Is there something I am missing? I am making a Object and drawing the image to the screen?

function Player()  //Object
{

this.PlayerHullMax = 1000;
this.PlayerHull = 1000;
 this.PlayerShieldMax = 1000;
this.PlayerShield = 347;
this.Experience = 2684;

//where on canvas memory
this.type = "Cruiser";
this.srcX = ShipSrcXPicker(type);
this.srcY = ShipSrcYPicker(type);
this.drawX = ShipdrawXPicker(type);
this.drawY = ShipdrawYPicker(type);
this.playerWidth = ShipWidthPicker(type);
this.playerHeight = ShipHeightPicker(type);
}

Player.prototype.draw = function()
{
ClearShipsCanvas();
ctxShips.globalAlpha=1;
 ctxShips.drawImage(spriteImage,this.srcX,this.srcY,this.playerWidth,this.playerHeight,this. drawX,this.drawY,this.playerWidth,this.playerHeight);
 };

function ShipSrcXPicker(type)
{
if (type == "Cruiser")

 {
    return 0;
 }
 }

function ShipSrcYPicker(type)
{
if (type == "Cruiser")

 {
    return 1385;
 }
}

function ShipdrawXPicker(type)
{
 if (type == "Cruiser")

 {
    return 100;
 }
}

function ShipdrawYPicker(type)
{
if (type== "Cruiser")

 {
    return 400;
 }
}


function ShipWidthPicker(type)
{
if (type == "Cruiser")

 {
    return 150;
 }
}

function ShipHeightPicker(type)
{
if (type == "Cruiser")

 {
    return 90;
 }
}
\$\endgroup\$
1
  • 6
    \$\begingroup\$ Question about JavaScript syntax/behavior, not related to games specifically. \$\endgroup\$ – Sean Middleditch Jun 3 '13 at 0:07
2
\$\begingroup\$

Next time you post, write what the error is.

ReferenceError: type is not defined

This means that the variable type is not defined. However, this.type is defined. So the line you point out should be changed to:

this.srcX = ShipSrcXPicker(this.type);

And all the subsequent lines should be changed similarly.

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.