Skip to content
Jamiras edited this page Oct 2, 2024 · 6 revisions

always_true()

Defines the clause "1==1". It is typically only used to move a PauseIf/ResetIf to an alt group:

byte(0x1234) == 8 && (always_true() || (never(byte(0x2345) == 12) && unless(byte(0x3456) == 6)))

This allows the achievement (core group) to trigger while the never is paused by the unless.

always_false()

Defines the clause "0==1". It is typically used for constructing alt chains, as a variable must have an initial value:

trigger = always_false()
for test in tests
    trigger = trigger || test
achievement(..., trigger = trigger)

If more than two alt groups exist, the always_false group will be removed from the final achievement code

format(format_string, parameters...)

Builds a string by inserting parameters into placeholders in the format_string.

For example:

stage_names = {
    1: "Downtown"
}
stage_1_label = format("Stage {0} - {1}", 1, stage_names[1])

Would set stage_1_label to "Stage 1 - Downtown"

substring(string, offset, length=0x7FFFFFFF)

Returns length characters of string, starting at offset (0-based). A negative offset indicates the returned value should start that far from the end of the string. A negative length indicates the returned value should stop that far from the end of the string.

bc  = substring("abcdef", 1, 2)  // take two characters starting at index 1
def = substring("abcdef", 3)     // take all remaining characters starting at index 3
e   = substring("abcdef", -2, 1) // starting two from end, take one character
cd  = substring("abcdef", 2, -2) // starting at index 2, take all but two characters

If the offset or length parameters extend beyond the length of the string, only characters at indices within the string will be returned. If all captured characters would be outside the string, an empty string is returned.

length(object)

Returns the number of elements in a dictionary or array, or the number of characters in a string.

range(start, stop, step=1)

Returns an array containing integers starting at start and continuing until stop.

If step is specified, the second item will be start+step, the third will be start+step*2, and so on until a value greater than stop would be generated. That value will be ignored.

array_map(inputs, predicate)

Returns an array generated by processing each item in inputs through predicate.

inputs is an array or a dictionary. If a dictionary is provided, the keys will be passed to the predicate.

predicate is a function that accepts a single input and returns an expression or constant constructed from that input. The expressions returned by predicate are stored in the new array that is returned by array_map.

array_contains(array, value)

Returns true if value is found in array.

dictionary_contains_key(dictionary, key)

Returns true if dictionary contains an entry for the specified key.

any_of(inputs, predicate)

Returns an expression that will evaluate true if any of the inputs matches the predicate.

inputs is an array or a dictionary. If a dictionary is provided, the keys will be passed to the predicate.

predicate is a function that accepts a single input and returns an expression constructed from that input. The expressions returned by predicate are joined with ||s.

all_of(inputs, predicate)

Returns an expression that will evaluate true if all of the inputs matches the predicate.

inputs is an array or a dictionary. If a dictionary is provided, the keys will be passed to the predicate.

predicate is a function that accepts a single input and returns an expression constructed from that input. The expressions returned by predicate are joined with &&s.

none_of(inputs, predicate)

Returns an expression that will evaluate true if all of the inputs do not match the predicate.

inputs is an array or a dictionary. If a dictionary is provided, the keys will be passed to the predicate.

predicate is a function that accepts a single input and returns an expression constructed from that input. The expressions returned by predicate are negated (!) and then joined with &&s.

sum_of(inputs, predicate)

Returns an expression that will calculate the sum of the inputs modified by the predicate.

inputs is an array or a dictionary. If a dictionary is provided, the keys will be passed to the predicate.

predicate is a function that accepts a single input and returns an expression constructed from that input. The expressions returned by predicate are added together with +.

tally_of(inputs, count, predicate)

Returns a tally expression where each comparison is generated by running the inputs through the predicate.

inputs is an array or a dictionary. If a dictionary is provided, the keys will be passed to the predicate.

predicate is a function that accepts a single input and returns an expression constructed from that input. The expressions returned by predicate are used in the tally expression.

assert(condition, message="")

Generates a processing error if condition is false. message defines what the error should say. If not specified, the message will be the condition as a string.