Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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;
 }
}
share|improve this question
6  
Question about JavaScript syntax/behavior, not related to games specifically. –  Sean Middleditch Jun 3 '13 at 0:07
add comment

closed as off topic by Sean Middleditch, Patrick Hughes, Byte56, msell, Maik Semder Jun 3 '13 at 7:57

Questions on Game Development Stack Exchange are expected to relate to game development within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

1 Answer

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.

share|improve this answer
add comment

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