Skip to content

Conversation

@BogdanLyopa
Copy link

New Functions for ArrayTools Extension

This PR adds three new useful functions for working with arrays and structures in GDevelop.

📋 Overview

Function Full Name Group Type
CopyVariable Copy variable Scene variables/Array creation Action
Filter Filter array Scene variables/Array manipulation Action
SortStructuresByField Sort structures by field Scene variables/Array manipulation Action

🔄 CopyVariable

Description

Copies a variable (structure or array) completely with all nested fields. Creates a real deep copy without any links.

Parameters

Parameter Type Description
SourceVariable variable Source variable (structure or array) to copy from
TargetVariable variable Target variable (structure or array) to copy to

Usage

Copy variable SourceVariable to TargetVariable

🔍 Filter

Description

Filters an array based on a comparison condition. Can filter arrays of numbers, strings, or structures. If OutputArray is not specified, the input array is mutated.

Parameters

Parameter Type Required Description
SourceArray variable Array to filter
FieldPath string Field name or path to check for structures (supports nested fields like "player.score")
Operator stringWithSelector Comparison operator: ==, !=, >, <, >=, <=
Value string Value to compare against (can be regex like /pattern/, number, boolean, or text)
OutputArray variable Output array (leave empty to mutate input array)

Usage

Filter array SourceArray where FieldPath Operator Value into OutputArray

Features

  • ✅ Supports filtering arrays of numbers, strings, and structures
  • ✅ Supports nested fields through dot notation (e.g., "player.score")
  • ✅ Supports different value types:
    • Regex: format /pattern/ (e.g., /^test/)
    • Numbers: automatically recognized
    • Boolean: "true" or "false"
    • Strings: any text
  • ✅ Can work in-place (mutate source array) or create a new array
  • ✅ Supports all standard comparison operators

Examples

Filtering numbers:

Filter array MyArray where "" > "10" into FilteredArray

Filtering structures:

Filter array Players where "score" >= "100" into HighScorers

Filtering with regex:

Filter array Names where "" == "/^John/" into Johns

📊 SortStructuresByField

Description

Sorts an array of structures by a specified field or path. Automatically detects if the value is a number or string and sorts accordingly.

Parameters

Parameter Type Description
Array variable Array of structures to sort
FieldPath string Field name or path to sort by (supports nested fields like "player.score")

Usage

Sort array Array by field FieldPath

Features

  • ✅ Automatically detects value type (number or string) for correct sorting
  • ✅ Supports nested fields through dot notation (e.g., "player.score")
  • ✅ Sorts in-place (mutates source array)
  • ✅ Numbers are always sorted before strings
  • ✅ Works only with arrays of structures

Examples

Sorting by simple field:

Sort array Players by field "score"

Sorting by nested field:

Sort array Players by field "player.stats.level"

✨ Benefits

These functions significantly extend the capabilities of working with arrays and structures in GDevelop:

  • CopyVariable: Allows creating independent copies of data without the risk of accidental changes
  • Filter: Provides a powerful tool for selecting elements from arrays based on complex conditions
  • SortStructuresByField: Simplifies sorting of complex data structures

@BogdanLyopa BogdanLyopa requested a review from a team as a code owner January 26, 2026 10:42
@D8H D8H added 🔄 Extension update An update for an existing extension 🔍 Reviewed extension An extension that is to be reviewed in great detail before merging. labels Jan 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🔄 Extension update An update for an existing extension 🔍 Reviewed extension An extension that is to be reviewed in great detail before merging.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants