Collection of useful functions for GameMaker Studio 2
Converts all elements in an array into a string separated by separator
0.0.1
array {array}
: The array to convert.[separator=","] {string}
: The element separator.
{string}
: Returns the joined string.
array_join(['a', 'b', 'c'], '~');
Reverses array
so that the first element becomes the last, the second element becomes the second to last, and so on.
0.0.1
array {array}
: The array to modify.
var _arr = [1, 2, 3];
array_reverse(_arr);
printf(_arr);
=> [ 3, 2, 1 ]
Draws a line using a sprite and stretching it to the correct dimensions.
0.0.1
sprite {real}
: Sprite index for drawing.x1 {real}
: First X position.y1 {real}
: First Y position.x2 {real}
: Second X position.y2 {real}
: Second X position.color {real}
: Line color.alpha {real}
: Line alpha.
draw_line_fast(spr_1px, 0, 0, 32, 32, c_blue, 1.0);
Draws a rectangle using a sprite and stretching it to the correct dimensions.
0.0.1
sprite {real}
: Sprite index for drawing.x {real}
: X position.y {real}
: Y position.width {real}
: Rectangle width.height {real}
: Rectangle height.color {real}
: Rectangle color.alpha {real}
: Rectangle alpha.outline {real}
: Whether to drawn only an outline.
draw_rectangle_fast(spr_1px, 0, 0, 32, 32, c_red, 1.0, false);
Converts all elements in a ds_list into a string separated by separator
0.0.1
id {real}
: The ds_list to convert.[separator=","] {string}
: The element separator.
{string}
: Returns the joined string.
ds_list_join(['a', 'b', 'c'], '~');
Reverses id
so that the first element becomes the last, the second element becomes the second to last, and so on.
0.0.1
id {real}
: The ds_list to modify.
var _list = ds_list_create();
ds_list_add(_arr, 1, 2, 3)
ds_list_reverse(_list);
printf(_list);
=> [ 3, 2, 1 ]
Prints a formatted string to the console
0.0.1
string {string}
: The string to print....args {any}
: Replacement values for the formatting.
printf("Hello {0}", "World");
=> "Hello World!"
Executes a script by name using an array of parameters, and returns the result.
0.0.1
name {string}
: The script to execute.args {array}
: Array of parameters to pass to the script.
{any}
: Result of script call.
script_execute_spread("printf", ["Hello World!"]);
=> "Hello World!"
Returns a formatted string
0.0.1
string {string}
: The string to format....args {any}
: Replacement values for the formatting.
{string}
: Formatted string.
stringf("Hello {0}", "World");
=> "Hello World!"
Reverses string
so that the first element becomes the last, the second element becomes the second to last, and so on.
0.0.1
string {string}
: The string to reverse.
{string}
: Reversed string.
var _str = "Hello World!",
_reversed = string_reverse(_str);
printf(_reversed);
=> "!dlroW olleH"
Splits string
by separator
.
0.0.1
string {string}
: The string to split.separator {string}
: The separator pattern to split by.[limit] {real}
: The length to truncate results to.
{array}
: Returns the string segments.
var _split = string_split("a,b,c", ",", 2);
printf(_split);
=> [ "a", "b" ]
Removes leading whitespace or specified characters from string
.
0.0.1
string {string}
: The string to trim.[chars=" "] {string}
: The characters to trim.
{string}
: Returns the trimmed string.
var _trimmed = string_ltrim(" abc ");
printf(_trimmed);
=> "abc "
Removes trailing whitespace or specified characters from string
.
0.0.1
string {string}
: The string to trim.[chars=" "] {string}
: The characters to trim.
{string}
: Returns the trimmed string.
var _trimmed = string_rtrim(" abc ");
printf(_trimmed);
=> " abc"
Removes leading and trailing whitespace or specified characters from string
.
0.0.1
string {string}
: The string to trim.[chars=" "] {string}
: The characters to trim.
{string}
: Returns the trimmed string.
var _trimmed = string_trim(" abc ");
printf(_trimmed);
=> "abc"
- Andrew Bennett - GML implementation - AndrewBGM
See also the list of contributors who participated in this project
This project is licensed under the MIT License - see the LICENSE.md file for details