Skip to content

Documentation

Collin Meyer edited this page Mar 26, 2022 · 1 revision

Setup

Download the latest release from the Releases tab. Drag the downloaded file into your IDE window. You can also press "Import Local Package" under the Tools Menu, and select the file.

Frog alarms is also available on the YoYo Marketplace!

Initialize

First, you'll need to initialize the FrogAlarms. Add the following code to the Create event of an object.
Note: The fa struct created here can hold many alarms.

// Create
fa = new FrogAlarms();

To count down all frog alarms that exist within the fa struct, call the run() function within the Step event.

// Step
fa.run();

Functions

.create(function, time, index)

A FrogAlarm can be created using the create() function. FrogAlarms start running when created.

Argument Type Description
function Function A function that will run when the alarm is finished.
time Number How long the alarm should run in frames
index String/Number Optional. Adding an index to an alarm allows it to be referenced after it has started. Alarms with the same index will not be restarted or recreated.
// Create
fa.create(
    function() {
        show_debug_message("Ribbit");
    },
    60
);

// Outputs `Ribbit` after 60 frames.

Adding an index prevents starting duplicate alarms

// Step
fa.create(
    function() {
        show_debug_message("Ribbit");
    },
    room_speed,
    "my_frog_alarm"
);

// Outputs `Ribbit` ONCE every second.

.pause(index)

Pauses the alarm.

Argument Type Description
index String/Number or Array of String/Numbers
fa.pause("my_frog_alarm");
fa.pause(["my_frog_alarm_2", 23]);
// Pauses FrogAlarms: my_frog_alarm, my_frog_alarm_2, and 23.

.resume(index)

Resumes a paused alarm.

Argument Type Description
index String/Number or Array of String/Numbers
fa.resume("my_frog_alarm");
fa.resume(["my_frog_alarm_2", 23]);
// Resumes FrogAlarms: my_frog_alarm, my_frog_alarm_2, and 23.

.remove(index)

Removes the alarm from the struct.
Note: FrogAlarms are auto-removed once they finish

Argument Type Description
index String/Number or Array of String/Numbers
fa.remove("my_frog_alarm");
fa.remove(["my_frog_alarm_2", 23]);
// Removes FrogAlarms: my_frog_alarm, my_frog_alarm_2, and 23.

.restart(index)

Sets the alarm's time to the duration

Argument Type Description
index String/Number or Array of String/Numbers
fa.restart("my_frog_alarm");
fa.restart(["my_frog_alarm_2", 23]);
// Restarts FrogAlarms: my_frog_alarm, my_frog_alarm_2, and 23.

.list(function)

Returns an array of FrogAlarm indices.

Argument Type Description
function Function Optional. A function for filtering alarms before they are returned. This function uses one argument. Each alarm's index will be passed into this argument. If this function returns false, list() will not include that index in the array.
show_debug_message( fa.list() );
// Outputs an array of all existing FrogAlarm indicies.

Alarms can be filtered using the optional function argument.

short_alarms = fa.list( function(alarm_idx) { return fa.get_time(alarm_idx) < 60; } );
fa.pause(short_alarms);
// This pauses all alarms with less than 60 frames remaining

.get_time(index)

Returns the current amount of time an alarm has remaining in frames.

Argument Type Description
index String/Number

.set_time(index, time)

Sets the time remaining for an alarm. If this time is greater than the alarm's duration, the duration will also be changed.

Argument Type Description
index String/Number
time Number Time in frames.

.get_duration(index)

Returns the duration of the alarm in frames.

Argument Type Description
index String/Number

.set_duration(index, duration)

Sets the duration of an alarm. This function will NOT adjust the alarm's time.

Argument Type Description
index String/Number
duration Number Time in frames.

.is_running(index)

Returns true if the alarm is running. Returns false if the alarm is paused or does not exist.

Argument Type Description
index String/Number

.exists(index)

Returns true if the alarm exists, false if it does not.

Argument Type Description
index String/Number