Add-ons / Notify Macro

This macro pops a message up that slides out from the right side of the screen, a short notification that's less distracting than a dialog or alert, for things like inventory changes, experience gains, or even achievements.

Author ChapelR
Website https://twinelab.net/custom-macros-for-sugarcube-2/#/notify-macro
Story format SugarCube 2
Last checked Mon Jul 22 2024
License Unlicense
Download notify.zip

Index

Overview

This macro pops a message up that slides out from the right side of the screen, a short notification that's less distracting than a dialog or alert, for things like inventory changes, experience gains, or even achievements.

📝 Note: Unlike most of my code, this macro requires you to install the CSS code as well in your story's Stylesheet section.

Macros

<<notify>>

<<notify>>

Syntax:<<notify [delay] [classList]>>...<</notify>>

The <<notify>> macro displays everything between it's tags in a small message box on the top right of the screen that slides in and slides out after a brief delay.

Arguments:

Usage:

/% a simple, two-second-long notification with no added classes %/
<<notify>>Achievement unlocked!<</notify>>

/% a one-second-long notification with the 'inventory-update' class %/
<<notify 1s 'inventory-update'>>Found gold.<</notify>>

/% a lengthy five-second-long notification %/
<<notify 5s>>$xp experience points earned.<</notify>>

READ: Documentation

JavaScript API

setup.notify()

setup.notify()

Syntax: setup.notify(message, delay, classes)

Simply a JavaScript version of the macro, for when you're working in JavaScript. Pass in the message to display as the first argument. Like with the macro, everything else is optional.

Returns: nothing.

Arguments:

Usage Notes

⚠️ Attention: Note that giving the player unlimited control over these notifications, or trying to show several at once or right after each other will cause them to trip over themselves as they try to animate, so try to keep them spaced out, and don't assign them to links or buttons you expect the player to press repeatedly.

Live demo

Demo Twee code:

:: Start
<<notify 5s 'inventory-update'>>Example notification.<</notify>>\
<<link 'Notify me!'>><<notify 2s 'inventory-update'>>You have been notified.<</notify>><</link>>