Event trigger with score

Started by SeeingRedStudios, Tue 08/04/2025 01:21:33

Previous topic - Next topic

SeeingRedStudios

Hey all, I've just gotten started with AGS and I'm havinh a great time learning and making my first game ever.

Is there a way to trigger a global script event once the player accumulates a certain score, or reaches a max score? Could be to trigger the end of the game, but I'm looking to trigger an event where the player receives an inventory item. I've scoured the forums and manual, all I seem to find are just ways to display the score.

I'm looking for something like:

if (score = 10)
 {
  player.AddInventory(item)
 }

Thanks!

Crimson Wizard

Hello. If you are using a built-in score feature (with GiveScore command), then engine will call "on_event" script function for it, with eEventGotScore parameter:
https://adventuregamestudio.github.io/ags-manual/Globalfunctions_Event.html#on_event

The code would look something like:
Code: ags
function on_event(EventType event, int data)
{
    if (event == eEventGotScore)
    {
         if (game.score == 10)
         {
              player.AddInventory(item);
         }
    }
}


On the other hand, if you are not using a built-in score feature, but have your own score variable, then you should write your own function which adds score and checks for certain score level.

SMF spam blocked by CleanTalk