PDA

View Full Version : having a problem...


johnish
06-19-2008, 02:07 AM
hey guys, i know this is a noob mistake.... but i have no ieda
i made a pong game and it obviously records a score..
the code below is on the ball


//This section is only processed once.
onClipEvent (load) {
var xspeed = 12;
var yspeed = 12;
score1 = 0;
score2 = 0;
}
//This section is processed every frame
onClipEvent (enterFrame) {
if (this._x>600) {
_root.score2 ++;
}
if (this._x<0) {
_root.score1 ++;
}
//Check if the pong block has gone below the stage area
if ((this._y+this._height)>Stage.height) {
//set the pong block to the bottom edge of the stage
this._y = Stage.height-this._height;
//set the pong block to move up
yspeed *= (-1);
}
//Check if the pong block has gone above the stage area
if (this._y<0) {
//set the pong block to the top edge of the stage
this._y = 0;
//set the pong block to move down
yspeed *= (-1);
}
//Check if the pong block has gone to the left or right of the stage area

if ((this._x+this._width<0) || (this._x>Stage.width)) {
//left side scored
if (this._x>Stage.width) {
_root.leftscore++;
}
//right side scored
if (this._x+this._width<0) {
_root.rightscore++;
}
//set the pong block to the middle of the stage
this._x = Stage.width/2;
//set the pong block to move in the opposite direction horizontally
xspeed *= (-1);
}

//move the x and y positions of the pong block
_x += xspeed;
_y += yspeed;
}


and that doesnt work. when it scores it displays NaN
ive also tried +=1
that just adds one.. ie score 1 then 11 then 111 so forth...

please help me out

gnomeontherun
06-19-2008, 02:48 AM
if (this._x>600) {
_root.score2++;
}
if (this._x<0) {
_root.score1++;
}


Start by removing the gap between the name and the ++; operand. If that doesn't work can you post the whole FLA somewhere?

johnish
06-19-2008, 10:49 AM
yeah... that didnt work... the fla is on
http://www.johnhatvani.com/tmp/pong.fla

gnomeontherun
06-19-2008, 06:26 PM
Take this code from the onClipEvent of the square and put it on the root track frame 1.
var score1:Number = 0;
var score2:Number = 0;
This makes sure the variables are typed as numbers, and I would also suggest that onClipEvent(load) to move the other two variables if you intend on offering ways to increase or decrese those values at the start of the game.

But then something funny happened, if the computer scored on me it gave it a score in increments of 2. Odd, but my score was going just fine. I didn't figure that one out at the moment, I can't spare hours on this, but maybe you can find it.