Howdy,
Wondering if someone had some advice for me. I have two frames in my game, the first one is where all the action takes place. The second frame has a small scene that plays when you fall off a cliff. Once you hit SPACE it takes you back to scene one.
My problem is that when I hit SPACE it refreshes the game and resets all the variables.
The only variable that I care about at the moment is life. This controls the amount of santa head icons at the top left of the screen. Whenever Santa falls off the cliff **life **subtracts by one. But! When it switches to the second frame and back again (to frame 1) it resets to **life = **3.
Here’s the script, the important bits are [color=Red]highlighted:[/color]
onClipEvent (load) {
this._x = 350;
this._y = 300;
_root._x= 0;
_root._y= 0;
vel_y = 0;
//this will be used for his jumping velocity//
started = true;
//this will be required when we make his movement//
jumping = false;
//this will be required when we make his jumping//
xspeed = 5;
//this is his movement speed//
this.stop();
//and this commands him to hault on //
//his standing sequence (asuming that you //
//made his standing sequence on his first frame) //
left = false;
//determines direction facing for animation
**[color=Red] life = 3;[/color]**
_root.gotoAndStop("1");
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.RIGHT)) {
if (_root.mario._x>=300) {
//or whatever you decide to set for his positions//
scroll = 5;
//setting his scrolling speed//
xspeed = 0;
//ceasing his movement//
this._x += 5;
_root._x -= scroll;
_root.lives._x += scroll;
_root.background._x -= scroll/9;
_root.close_background._x -= scroll/4;
} else {
xspeed = 5;
}
} else if (Key.isDown(Key.LEFT)) {
if (_root.mario._x<=500) {
//or whatever you decide to set for his positions//
scroll = 5;
xspeed = 0;
this._x -= 5;
_root._x += scroll;
_root.background._x += scroll/9;
_root.close_background._x += scroll/4;
_root.lives._x -= scroll;
} else {
xspeed = 5;
}
}
}
onClipEvent (enterFrame) {
if (started) {
if (move) {
if (Key.isDown(Key.LEFT)) {
this.gotoAndStop("run_left");
left = true;
}
if (Key.isDown(Key.RIGHT)) {
this.gotoAndStop("run_right");
left = false;
}
}
}
}
onClipEvent (enterFrame) {
if (started) {
if (Key.isDown(Key.LEFT)) {
this._x -= xspeed;
}
if (Key.isDown(Key.RIGHT)) {
this._x += xspeed;
}
if (Key.isDown(Key.UP) && !jumping) {
if (left == false) {
this.gotoAndStop("jump_right");
}
if (left == true) {
this.gotoAndStop("jump_left");
}
move = false;
vel_y = 17;
jumping = true;
}
if (jumping == true) {
vel_y -= 1;
if (vel_y<=-17) {
vel_y = -17;
}
this._y -= vel_y;
if (vel_y>0) {
_root.platform._y += vel_y/5;
} else {
_root.platform._y += vel_y/3;
if (_root.platform._y<272.2) {
_root.platform._y = 272.2;
}
}
}
if (!_root.platform.hitTest(this._x+25, this._y+10, true) && !jumping) {
fall += 1;
move = false;
if (fall>17) {
fall = 17;
}
this._y += fall;
if (fall>0) {
_root.platform._y -= 17/3;
if (_root.platform._y<272.2) {
_root.platform._y = 272.2;
}
}
}
for (i=1; i<50; i++) {
if (!_root.platform.hitTest(_x+25, _y-i, true)) {
_y -= i-3;
break;
} else if (_root.platform.hitTest(_x+25, _y-i, true)) {
fall = 0;
vel_y = 0;
jumping = false;
move = true;
}
}
**[color=Red]//Life counter
if (life==4) {
_root.lives.gotoAndStop("4_lives");
}
if (life==3) {
_root.lives.gotoAndStop("3_lives");
}
if (life==2) {
_root.lives.gotoAndStop("2_lives");
}
if (life==1) {
_root.lives.gotoAndStop("1_lives");
}
//Decrease life counter if you fall in a pit
if (this._y>290 && this._y<300) {
life--;
_root.gotoAndStop("lost_1lives");
this._x = 350;
this._y = 300;
_root._x= 0;
_root._y= 0;
}
}
}
[/color]**//keyup status
onClipEvent (keyUp) {
// keyUp property
if (Key.getCode() == Key.RIGHT) {
this.gotoAndStop("idle_right");
} else if (Key.getCode() == Key.LEFT) {
this.gotoAndStop("idle_left");
} else if (Key.getCode() == Key.UP) {
if (left == false) {
this.gotoAndStop("idle_right");
}
if (left == true) {
this.gotoAndStop("idle_left");
}
} else if (Key.getCode() == Key.UP && Key.LEFT) {
this.gotoAndStop("idle_left");
} else if (Key.getCode() == Key.UP) {
this.gotoAndStop("idle_right");
}
}
SWF: http://www.rhine.ca/test/
FLA (MX 2004): http://www.rhine.ca/test/index.fla
FLA (MX): http://www.rhine.ca/test/index_mx.fla
Cheers for any help in advance. I can’t offer any specialty cooking at the moment because I still owe Cybernoid some wagamamas (Sorry Cyber…).