Managing Lives

All talk relating to Edward, the Flash platform game engine. (Forum is now locked)

Managing Lives

Postby Fliberdigibit » Sat Jan 16, 2010 1:45 pm

hello all!

I've been working on a Edward Engine platform game for a few weeks now and I'm finally at a point where I need to start manipulating code to fit my own needs. There's not much to change around b/c I want to hold somewhat true to Sophies original engine.

It comes down to two functions I want to add to code: One being a playerLives function to update and display how many lives the player has and the other being a function that counts how many collectables (in my case "MOLICONS") the player has collected and checks if it reaches a certain amount, if it is then it updates the playerLives by adding one and resets the collectables to 0.

I'm what some might call a novice (if even that) when it comes to AS3, but I've been playing around with the code to try to come up with a solution for these two problems. The playerLives function is somewhat easy (or so I thought). I created a variable on the initialization frame called playerLives that is linked to a dynamic text field like the other variables and it has a value of 3. I then created a function called showLives() which as you guessed it, displays the number of lives the player has on the screen. The showLives method is called in onGameTick. I placed the code for updating playerLives by subtracting 1 when dying in the respawn when dying code. First it checks to see if playerLives is equal to 0, if it is then it starts back on frame two of the main timeline and resets the playerLives to 3, if it isn't then it subtracts 1 from playerLives.

In theory this code should work, but when put into practice I ran into a bug. Everything works just fine until playerLives equals 0 and the gotoAndStop takes us back to frame 2 on the main timeline. As soon as you click the play button the game glitches and the playerMC spazzes through its animations.

I'd like to tackle this problem before I start looking into the collectables bit. Any information or suggestions from anybody would be much appreciated.

Thanks,

Flibers
User avatar
Fliberdigibit
Newcomer
 
Posts: 6
Joined: Tue Jan 12, 2010 8:09 am
Location: NC

Re: Managing Lives

Postby Fliberdigibit » Tue Jan 19, 2010 2:53 pm

I've been trying to get this life management system down for the past 3 days now, and it seems like I've almost got it, cept one little snag, and I can't seem to figure out what the problem is..... :ARGH:

the lives subtract by one every death like it's supposed to and when the lives equal 0 it jumps back to frame 2 like it's supposed to. The problem only occurs when you click the play button the second time around. Player movement is debilitated and it jumps through every animation in the Player MC.

ANYBODY??????
User avatar
Fliberdigibit
Newcomer
 
Posts: 6
Joined: Tue Jan 12, 2010 8:09 am
Location: NC

Re: Managing Lives

Postby Fliberdigibit » Wed Jan 20, 2010 1:33 pm

wait a sex... Okay, it turns out I did do everything right when it comes to managing my lives, except I forgot to remove my eventListener. Simple mistake that took me 4 days to figure out... :shazbot:

on to the next problem. Now I have to figure out how to adjust the collectables code to add a life every ten collected. I might be able to figure this one out on my own as well but any suggestions would definitely speed up the process.

thanx,
Flibers
User avatar
Fliberdigibit
Newcomer
 
Posts: 6
Joined: Tue Jan 12, 2010 8:09 am
Location: NC

Re: Managing Lives

Postby thatjoshguy » Sat Jan 30, 2010 7:54 pm

Maybe create a new global variable "$numCollected = 0"
then for each item collected:

$numCollected++;
if $numCollected == 10 {
$lives++; //increment lives
$numCollected = 0; // reset counter to 0
}

syntax isn't correct I'm sure, I come from a PHP background, not AS. Something similar should in fact work however.
thatjoshguy
Power Player
 
Posts: 39
Joined: Fri Apr 17, 2009 5:58 pm


Return to Edward Topics

Who is online

Users browsing this forum: No registered users and 1 guest

cron