Jump to content


Photo

Extra life a certain amount of points


  • Please log in to reply
7 replies to this topic

#1 NEPC

NEPC

    GMC Member

  • GMC Member
  • 46 posts
  • Version:GM8.1

Posted 16 May 2012 - 12:47 AM

Just started another project, and I want the player to a get an extra life when the player gets 10,000 points. But when I tried, the player just gets infinite lives.
Please help!
  • 0

#2 JAk HAk

JAk HAk

    sepius fidelis

  • New Member
  • 713 posts
  • Version:GM:HTML5

Posted 19 May 2012 - 06:41 AM

Just started another project, and I want the player to a get an extra life when the player gets 10,000 points. But when I tried, the player just gets infinite lives.
Please help!

Every 10'000 points:
//Create
bonus = 1;
points = 0;

//Step
if (points >= bonus*10000) {
  bonus += 1;
  lives += 1;
}

After first 10'000 points:
//Create
bonus = false;
points = 0;

//Step
if (points >= 10000 && !bonus) {
  bonus = true;
  lives += 1;
}

  • 0

#3 Chronic

Chronic

    Administrator

  • Global Moderators
  • 2721 posts
  • Version:GM:Studio

Posted 19 May 2012 - 07:02 AM

What i normally do for something like this is to create a script that increase your score, and at the same time increase another variable used to determine when to give an extra life.

The set up would be something like this

Create:
score = 0;
bonusPoints = 0;

Create a script and name it something appropriate, for example increase_score

Script increase_score:
score += argument0;
bonusPoints += argument0;

if (bonusPoints >= 10000) {
  bonusPoints -= 10000;
  lives += 1
}

The reason i subtract 10000 from bonusPoints instead of setting to 0 again is for any overflow. For example if you're at 9999 and you gain 1000 points (10999), resetting to 0 would lose 999 points causing issues between the score and when the player expects to get the next life.

Now just use that script every time you want to award points to the player, where argument0 is the amount you want to award.

increase_score(100);

  • 0

#4 Desert Dog

Desert Dog

    GMC Member

  • Global Moderators
  • 6409 posts
  • Version:Unknown

Posted 19 May 2012 - 08:19 AM

I liked how the Asteroids example(the one that comes with GM) did it.

Step event:
if ((score div 10000) != (lastscore div 10000))
{
       lives+=1;
}
lastscore=score;

  • 0

#5 NEPC

NEPC

    GMC Member

  • GMC Member
  • 46 posts
  • Version:GM8.1

Posted 22 May 2012 - 08:44 PM


Just started another project, and I want the player to a get an extra life when the player gets 10,000 points. But when I tried, the player just gets infinite lives.
Please help!

Every 10'000 points:
//Create
bonus = 1;
points = 0;

//Step
if (points >= bonus*10000) {
  bonus += 1;
  lives += 1;
}

After first 10'000 points:
//Create
bonus = false;
points = 0;

//Step
if (points >= 10000 && !bonus) {
  bonus = true;
  lives += 1;
}

It won't work. I installed everything correctly!
  • 0

#6 Desert Dog

Desert Dog

    GMC Member

  • Global Moderators
  • 6409 posts
  • Version:Unknown

Posted 22 May 2012 - 09:18 PM

Did you try my one?
  • 0

#7 NEPC

NEPC

    GMC Member

  • GMC Member
  • 46 posts
  • Version:GM8.1

Posted 01 July 2012 - 08:09 PM

Did you try my one?

That one's broken too.
  • 0

#8 Desert Dog

Desert Dog

    GMC Member

  • Global Moderators
  • 6409 posts
  • Version:Unknown

Posted 01 July 2012 - 08:39 PM

What's broken about it? I can assure you, the code works.. unless you give me some errors/report on what is happening, I cannot help you.

One possible error you might be experiencing is an 'unknown variable lastscore'. If so, simply put
lastscore=score
in the create event. This is called 'initializing' the variable.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users