Options
All
  • Public
  • Public/Protected
  • All
Menu

Module common

The common library defines basic functionality that may be useful to any script. There is no need to explicitly use it; it is automatically included in every script.

Index

Type aliases

Color

The Settings.Colour Java class.

Colour

The Settings.Color Java class.

Font

The standard java.awt.Font class.

Language

The Language Java class.

Region

The Settings.Region Java class.

Region2D

The Settings.Region2D Java class.

ResourceKit

The ResorceKit Java class.

Settings

The Settings Java class.

URL

The standard java.net.URL class, representing a Uniform Resource Locator such as https://strangeeons.cgjennings.ca.

arkham

arkham: JavaPackage<"arkham">

A shortcut for the ca.cgjennings.apps.arkham package.

ca

A reference to the ca root package.

gamedata

gamedata: JavaPackage<"gamedata">

A reference to the gamedata root package.

java

java: JavaPackage<"java">

A reference to the java root package.

javax

javax: JavaPackage<"javax">

A reference to the javax root package.

org

A reference to the org root package.

resources

resources: JavaPackage<"resources">

A reference to the resources root package.

swing

swing: JavaPackage<"swing">

A shortcut for the javax.swing package.

Variables

Const Component

A reference to the game component edited by the active editor tab, or null if none. If not null, then the Editor is an instance of AbstractGameComponentEditor, and the game component is an instance of GameComponent. (If it is a DIY component, it will be an instance of the DIY subclass.)

Const Editor

A reference to the active editor tab, or null if none. All editors are a subclass of the StrangeEonsEditor class.

Const Eons

A reference to the main application object, an instance of the StrangeEons class.

Const Patch

Patch: object

This object defines some helper functions that can be used to modify or restore settings. This can be used to change otherwise inaccessible user preferences, or to "hack" new game components from existing components by changing their private settings.

Type declaration

  • apply: function
    • apply(...keyValuePairs: string[]): void
    • Writes zero or more pairs of settings into user settings and then writes the user settings to disk. The new values will override the application defaults.

      The arguments declare the keys to replace and the values to replace them with as follows:

      Patch.apply("key1", "value1", "key2", "value2", ...)

      Parameters

      • Rest ...keyValuePairs: string[]

        an even number of arguments forming a sequence of key, value pairs; each value is written to the settings under the matching key

      Returns void

  • card: function
    • Changes zero or more pairs of the specified component's private settings.

      The arguments declare the keys to replace and the values to replace them with as follows:

      Patch.apply(component, "key1", "value1", "key2", "value2", ...)

      Note that the built-in Component always refers to the currently edited game component, if any. (Otherwise it is null.)

      Parameters

      • component: JavaObject<"arkham.component.GameComponent">

        the component to modify

      • Rest ...keyValuePairs: string[]

        an even number of arguments forming a sequence of key, value pairs; each value is written to the settings under the matching key

      Returns void

  • cardFrom: function
    • Modifies the private settings of a game component by merging in all of the settings stored in a resource file.

      Parameters

      Returns void

  • cardRestore: function
    • Removes one or more private settings from a component, resetting them to whatever value they inherit from the component's parent settings. This is not necessarily the same as resetting them to the component's initial state, as some settings may only have been defined on the component.

      Parameters

      Returns void

  • restore: function
    • restore(...keys: string[]): void
    • Deletes zero or more user settings, then writes the user settings to disk. This causes the specified settings to revert to the application default.

      Parameters

      • Rest ...keys: string[]

        the names of zero or more keys to be restored

      Returns void

  • temporary: function
    • temporary(...keyValuePairs: string[]): void
    • Changes zero or more pairs of settings until the end of the current session. The settings will return to their previous value the next time the application runs.

      The arguments declare the keys to replace and the values to replace them with as follows:

      Patch.temporary("key1", "value1", "key2", "value2", ...)

      Parameters

      • Rest ...keyValuePairs: string[]

        an even number of arguments forming a sequence of key, value pairs; each value is written to the settings under the matching key

      Returns void

Const PluginContext

If this is a plug-in script that is being called into by the application, this is a reference to the PluginContext that describes the context in which the call is being made.

Const confirm

confirm: object

Type declaration

    • (promptMessage: string, title?: string): boolean
    • Prompts the user to confirm an action by choosing OK or Cancel. Returns true if the user chooses OK, otherwise false. For example:

      confirm("Proceed?");

      Parameters

      • promptMessage: string

        a message to display

      • Optional title: string

        an optional title for the prompt window

      Returns boolean

      true if the user confirms the action

  • choose: function
    • choose(promptMessage: string, title: string, ...option: string[]): number
    • Prompts the user to choose between one or more buttons. The first button is highlighted as a default option. Returns -1 if the user cancels the dialog. Otherwise returns 0 if the user selected the first option, 1 if the user selected the second option, and so on. For example:

      confirm.choose("Favourite colour?", null, "Green", "Red", "Blue");

      Parameters

      • promptMessage: string

        a message to display

      • title: string

        an optional title for the prompt window

      • Rest ...option: string[]

        one or more button labels

      Returns number

      the number of the selected option, counting from 0, or -1 if cancelled

  • confirm: function
    • confirm(promptMessage: string, title?: string): boolean
    • An alternative name for confirm. Prompts the user to confirm an action by choosing OK or Cancel (localized if possible). Returns true if the user chooses OK, otherwise false. For example:

      confirm.confirm("Proceed?");

      Parameters

      • promptMessage: string

        a message to display

      • Optional title: string

        an optional title for the prompt window

      Returns boolean

      true if the user confirms the action

  • yesno: function
    • yesno(promptMessage: string, title?: string): boolean
    • Prompts the user to confirm an action by choosing Yes or No (localized if possible). Returns true if the user chooses Yes, otherwise false. For example:

      confirm.yesno("Do you agree?");

      Parameters

      • promptMessage: string

        a message to display

      • Optional title: string

        an optional title for the prompt window

      Returns boolean

      true if the user confirms the action

Const global

global: object

The global scope. This is an alternate name for self.

Const self

self: object

The global scope. This can be used to access a global variable that has been aliased by a local variable.

let variable = 42;
function anotherScope() {
  let variable = "aliased";
  println(variable); // prints aliased
  println(self.variable); // prints 42
}
anotherScope();

Const sourcefile

sourcefile: string | "Quickscript"

The path or URL that identifies the location of the source file of the running script. If the script is being run directly from a code editor, this will be the string "Quickscript".

Functions

alert

  • alert(message: string, isErrorMessage: boolean): void
  • Displays a message to the user. If clicked, the message will disappear instantly. Otherwise, if it is a plain message and not a warning or error message, it fades away over time. For example:

    alert("Caution:\nFloor is slippery when wet", false);

    Parameters

    • message: string

      the message to display

    • isErrorMessage: boolean

      if true, the message is presented as an error; if false, as a warning; if not specified, as a plain message

    Returns void

assert

  • assert(condition: boolean, message: string): void
  • If debugging is enabled in user preferences, this will check is the specified condition is true, and if not it will throw an error including the specified message. If debugging is not enabled, the condition is evaluated but the function otherwise has no effect.

    Parameters

    • condition: boolean

      the condition which must be true for the script to continue

    • message: string

      an error message to print when the assertion fails

    Returns void

debug

  • debug(format: string, ...args: string[]): void
  • If debugging is enabled in user preferences, prints an optionally formatted string to the application log. The log can be viewed from the console by right clicking, or by using the Log Viewer.

    see

    sprintf

    Parameters

    • format: string

      the text to log

    • Rest ...args: string[]

      optional arguments referenced by format specifiers in format

    Returns void

exit

  • exit(): void
  • Stops executing the script. If the script attached event listeners to objects or started other threads, they will continue to operate.

    Returns void

print

  • print(...obj: any[]): void
  • Prints an object to the script console. You may pass multiple arguments to this function; the arguments will be printed in sequence. For example:

    print("Hello");

    Parameters

    • Rest ...obj: any[]

      the object to be printed

    Returns void

printf

  • printf(format: any, ...args: any[]): void
  • printf(language: Language, format: any, ...args: any[]): void
  • Prints a formatted message string. The effect is the same as formatting the string with sprintf and then printing the result. Formatting will be localized using the interface language. For example:

    printf("Your lucky number is %d\n", 1 + Math.random()*100);

    Parameters

    • format: any

      the format string

    • Rest ...args: any[]

      arguments referenced by the string's format specifiers

    Returns void

  • Prints a formatted message string. The effect is the same as formatting the string with sprintf and then printing the result. For example:

    let languages = [new Language("en"), new Language("fr")];
    for(let lang of languages) {
        printf(lang, "In %s, the decimal of 1/2 is %.1f\n", lang.locale.displayName, 1/2);
    }

    Parameters

    • language: Language

      the language or locale used to localize the formatting, or null for no localization

    • format: any

      the format string

    • Rest ...args: any[]

      arguments referenced by the string's format specifiers

    Returns void

println

  • println(...obj: any[]): void
  • Prints an object to the script console, then starts a new line. You may pass multiple arguments to this function; the arguments will be printed in sequence, then a new line will be started.

    for(let i=1; i<=10; ++i) println(i);

    Parameters

    • Rest ...obj: any[]

      the object to be printed

    Returns void

prompt

  • prompt(promptMessage?: string, initialValue?: string): string | null
  • Displays a prompt to the user and waits for them to enter a value, returning the value.

    Parameters

    • Optional promptMessage: string

      a message to display

    • Optional initialValue: string

      a default value for the prompt field

    Returns string | null

    the entered value, or null if the prompt was cancelled

sleep

  • sleep(msDelay?: number): boolean
  • Pauses script execution for the specified period of time. Returns true if you interrupt the sleep period from another thread; otherwise false. Calling this from the main thread will cause the application to be unresponsive while sleeping; use caution when choosing a sleep duration.

    Parameters

    • Optional msDelay: number

      the time to sleep, in milliseconds (default is 1000)

    Returns boolean

    true if the sleep was interrupted, otherwise false

sprintf

  • sprintf(format: any, ...args: any[]): void
  • sprintf(language: Language, format: any, ...args: any[]): void
  • Returns a formatted string using the %-format string and arguments. Formatting will be localized using the interface language.

    Formatting behaviour is similar to Java's String.format method, but %i is allowed as a synonym of %d and numeric arguments will be coerced, if necessary, to fit the conversion type. For example, passing a number as the argument for a %d conversion will coerce the number to an integer type rather than cause an error. the result.

    Parameters

    • format: any

      the format string

    • Rest ...args: any[]

      arguments referenced by the string's format specifiers

    Returns void

  • Returns a formatted string using the %-format string and arguments.

    Formatting behaviour is similar to Java's String.format method, but %i is allowed as a synonym of %d and numeric arguments will be coerced, if necessary, to fit the conversion type. For example, passing a number as the argument for a %d conversion will coerce the number to an integer type rather than cause an error.

    Parameters

    • language: Language

      the language or local used to localize the formatting, or null for no localization

    • format: any

      the format string

    • Rest ...args: any[]

      arguments referenced by the string's format specifiers

    Returns void

useGameLanguage

  • useGameLanguage(language: Language): void
  • Sets the Language used to look up game strings using #key-name identifiers. By default this is the global game language.

    Parameters

    • language: Language

      the localized string database to use for # variables

    Returns void

useInterfaceLanguage

  • useInterfaceLanguage(language: Language): void
  • Sets the Language used to look up interface strings using @key-name identifiers. By default this is the global interface language.

    Parameters

    • language: Language

      the localized string database to use for @ variables

    Returns void

useLibrary

  • useLibrary(libraryName: string): void
  • Imports the specified library into the current script. The result is the same as if the code in the library was pasted at that point in your script. The library can either be the name of one of the standard scripting libraries or else a res:// URL pointing to a script resource.

    If the same library is imported with useLibrary multiple times in the same script, only the first call has any effect.

    Examples:

    // import standard library "markup"
    useLibrary("markup");
    // import user library from a plug-in, located at
    // resources/myname/myplugin/mylib.js
    useLibrary("res://myname/myplugin/mylib.js");

    Parameters

    • libraryName: string

      name of standard library, or resource path

    Returns void

useSettings

  • Sets the Settings source that will be used to get and set settings using the $setting-key syntax.

    By default, a script that uses this syntax will read and write the global (shared) settings, except for DIY scripts which use the private settings of their DIY game component object. This function allows you to choose a different Settings object to use. The specified source can be any of the following:

    • a Settings instance;
    • a GameComponent (to use the component's private settings);
    • or null (to use the global shared settings).

    Parameters

    Returns void

Methods

#

  • #(key: string, ...args: any[]): void
  • The # function looks up a game language string. This can be used analogously to a #key-name identifier to look up a key name that is composed on the fly, as in #("key-" + n). If passed more than one argument, it will look up the string for the first argument, then use the remaining arguments to format it as if by using sprintf.

    The Language that is searched for the specified key can be changed by calling useGameLanguage.

    Parameters

    • key: string

      the key to look up in the game language database

    • Rest ...args: any[]

      optional arguments that will be used to format the string

    Returns void

$

  • $(key: string, ...args: any[]): void
  • The $ function looks up a setting key. This can be used analogously to a $key-name identifier to look up a key name that is composed on the fly, as in $("key-" + n).

    The Settings that are searched for the specified key can be changed by calling useSettings.

    Parameters

    • key: string

      the key to look up in the game language database

    • Rest ...args: any[]

      optional arguments that will be used to format the string

    Returns void

@

  • @(key: string, ...args: any[]): void
  • The @ function looks up a user interface string. This can be used analogously to an @key-name identifier to look up a key name that is composed on the fly, as in @("key-" + n). If passed more than one argument, it will look up the string for the first argument, then use the remaining arguments to format it as if by using sprintf.

    The Language that is searched for the specified key can be changed by calling useInterfaceLanguage.

    Parameters

    • key: string

      the key to look up in the interface language database

    • Rest ...args: any[]

      optional arguments that will be used to format the string

    Returns void