clone

clone

> Functions

Copies the value value passed as a parameter, level levels deep, and returns the copy. For an array, for example, clone(array, 1) copies the array but not its elements, while clone(array, 2) copies the array as well as all its elements.

Parameters
Return
TypeScript

In JavaScript, there is no native equivalent: structuredClone is not available in the Leek Wars engine. For plain data — numbers, strings, arrays, simple objects — JSON.parse(JSON.stringify(value)) does the job, but it loses Maps, Sets, functions and undefined values; otherwise, write a recursive copy. Above all, { ...object } and [...array] only copy the first level, unlike clone.

Python

In Python, copy.deepcopy(value), from the copy module, makes a deep copy like clone, but with no notion of level: the copy is always complete. copy.copy(value) makes a shallow copy, where the sub-lists stay shared with the original. Game API objects (Cell, Leek…) are duplicated too, but they are simple read-only wrappers: the copy stays equal to the original (==) and refers to the same element of the fight.