Special event triggered by score >= 20, only if cEgo has not yet been in room 5

Started by Barn Owl, Wed 23/04/2025 00:39:18

Previous topic - Next topic

Barn Owl

Greetings once again all. Hope everyone is well.

I'm getting much better at creating a functional script (with the emphasis on function) without help.

I think if work on this I can figure it out. However, if anyone is bored and/or willing to point me in the right direction, I would certainly appreciate it.

So, my game is somewhat broken up into areas. Let's say rooms 1 through 4 are area A. Room 5 begins area B. Currently, the player must score a few points in area A before area B becomes available. So far so good.

So for the purpose of this example let's say there are 20 possible points in area A, and area B opens up when the player has scored 5 points or more.

I would like to add a secret bonus for the player that scores 20/20 points before, and only before, moving on to area B.

So, as I'm thinking it through typing here, the solution must be to create a bool that becomes true when entering area B. And if 20 points are scored while the bool is false, the secret bonus occurs...

I think I can cobble that code together. Yet it's all still quite new to this old dog, er, owl.

Anyhow, respond only if you feel like doing so.

As always, happy creating to all.


Khris

You can use a custom function like this:
Code: ags
// global header
import GiveScoreAreaA(int score);

// global script
int score_area_a;

function GiveScoreAreaA(int score) {
  GiveScore(score);
  score_area_a += score;
  if (score_area_a == 20) {
    // secret bonus code
  }
}

Now call GiveScoreAreaA(5); instead of GiveScore(5); in rooms 1-4.

However if the player always enters area B via room 5, all you really need is a suitable check in room 5:
Code: ags
// room event "first time player enters room"
function room_FirstLoad() {
  if (game.score == 20) {
    // secret bonus code
  }
}


Barn Owl

Hi Crimson Wizard, indeed, I've been rocking Game.DoOnceOnly over here. I've been updating my GiveScore(); scripts with Game.DoOnceOnly IDs. It's making the game more fun to play, I believe, which is always nice.

In this case, the player is able to exit after a score of 5, and after leaving they can always come back. However, if they rack up a score of 20 before they exit, they get a bonus event.

But if they exited with between 5-19 points the first time, the bonus is no longer attainable. Even if they come back later with 20 points or more.

I think I'm slowly getting the hang of this over here.

Much appreciated Crimson and Khris. Your assistance continues to be a great help.

SMF spam blocked by CleanTalk