Difference between revisions of "Alert Message"

From RPG Creation Kit
Jump to navigation Jump to search
(Created page with "The '''Alert Message''' is the pop-up text used to notify the Player that something happened in the game. It's what appears on screen when you gain XP ("+100 XP"), when you receive items ("Iron Bow added!"), when you learn a new spell ("You learn: Fireball") and in many other situations. File:Alertmsg 1.pngThe Alert Message is part of the Player's UI, you can find it inside the ''RckPlayer'' prefab, and it is exposed as a singleton ('''AlertMessage.instance'''), so...")
 
 
Line 1: Line 1:
The '''Alert Message''' is the pop-up text used to notify the Player that something happened in the game. It's what appears on screen when you gain XP ("+100 XP"), when you receive items ("Iron Bow added!"), when you learn a new spell ("You learn: Fireball") and in many other situations.
The '''Alert Message''' is the pop-up text used to notify the Player that something happened in the game. It's what appears on screen when you gain XP ("+100 XP"), when you receive items ("Iron Bow added!"), when you learn a new spell ("You learn: Fireball") and in many other situations.


[[File:Alertmsg 1.png]]The Alert Message is part of the Player's UI, you can find it inside the ''RckPlayer'' prefab, and it is exposed as a singleton ('''AlertMessage.instance'''), so it is accessible at anytime from anywhere in your code.
[[File:Alertmsg 1.png]]
 
The Alert Message is part of the Player's UI, you can find it inside the ''RckPlayer'' prefab, and it is exposed as a singleton ('''AlertMessage.instance'''), so it is accessible at anytime from anywhere in your code.


==Showing an Alert Message from a script==
==Showing an Alert Message from a script==

Latest revision as of 11:35, 18 July 2026

The Alert Message is the pop-up text used to notify the Player that something happened in the game. It's what appears on screen when you gain XP ("+100 XP"), when you receive items ("Iron Bow added!"), when you learn a new spell ("You learn: Fireball") and in many other situations.

Alertmsg 1.png

The Alert Message is part of the Player's UI, you can find it inside the RckPlayer prefab, and it is exposed as a singleton (AlertMessage.instance), so it is accessible at anytime from anywhere in your code.

Showing an Alert Message from a script

To show an Alert Message, all you have to do is call InitAlertMessage() on the instance:

AlertMessage.instance.InitAlertMessage("Here goes your message.", AlertMessage.DEFAULT_MESSAGE_DURATION_MEDIUM);

The method takes the following parameters:

  • Text: the message to display.
  • Duration: how long (in seconds) the message stays on screen. You can pass any value you want, but for consistency you may want to use one of the default durations defined in the AlertMessage class: DEFAULT_MESSAGE_DURATION_SHORT (1.5s), DEFAULT_MESSAGE_DURATION_MEDIUM (3s) and DEFAULT_MESSAGE_DURATION_LONG (5s).
  • Allow Duplication (optional): see the section below.

You can call it from any of your gameplay code: Item Scripts, Quest Scripts, Result Scripts and so on. Since the duration runs on unscaled time, the message will behave correctly even while the game is paused, for example when the Player has the inventory open.

The Alerts Queue

Only one Alert Message can be displayed at a time. If you init a message while another one is already on screen, the new one is not lost: it is added to a queue, and it will be displayed as soon as the current one (and the ones queued before it) expires.

There is one exception: if the message you are initing has the same text of the one currently displayed, it is discarded. This avoids stacking a wall of identical pop-ups when the Player repeats the same action quickly (buying five items in a row would queue five "Transaction Completed!" otherwise). If for some reason you do want the same message to be queued multiple times, pass true to the allowDuplication parameter.

Showing an Alert Message from a Consequence

You don't necessarily need a script to show an Alert Message: the Consequences System has a dedicated Consequence type for it, called AlertMessage.

Just add a new Consequence, set its type to AlertMessage and fill the Alert Message text and the duration. When the Consequence fires, the pop-up will be displayed. See Creating A New Consequence if you don't know how Consequences work.

Usually Alert Messages are mostly used with consequences inside the Dialogues:

Alertmsg 2.png

Customizing the look

The pop-up itself is a UI element with an AlertMessageUIElement component, which simply holds a reference to the TextMeshPro text that gets filled with the message. To change how the Alert Message looks (font, size, position, background...), edit that UI element inside the RckPlayer prefab.

Alert Message vs Tutorial Alert Message

Don't confuse the Alert Message with the Tutorial Alert Message: they are two different things.

The Alert Message is a passive notification, it appears, stays on screen for its duration and disappears by itself, without ever interrupting the Player.

The Tutorial Alert Message (TutorialAlertMessage.instance) is the message box used for the tutorials of the Demo: calling OpenMessage() pauses the game, unlocks the cursor and displays a window that the Player has to close with a button before continuing. There is also an OpenMessageAfterDialogueEnds() version that waits for the current conversation to end before popping up. Use it when the Player really has to read what you are saying, and use the regular Alert Message for everything else.

Here is an example of the Tutorial Alert Message in use:

Tutorialalertmessage.png