You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
**It's not an error in javascript (which is more DANGEROUS)**, the actually modifed value is just a copy of `node.position`.
71
71
72
+
## Godot Data Structures
73
+
74
+
Godot has its own types that represent arrays and dictionaries. Godot engine methods are passed and return these types rather than JavaScript arrays/objects.
75
+
76
+
GodotJS provides convenience APIs to make working with these data structures easier.
77
+
78
+
### Creating Godot Arrays
79
+
80
+
You can convert JavaScript arrays to Godot arrays using `GArray.create`.
81
+
82
+
```ts
83
+
const js_arr = [1, 2, 3];
84
+
const godot_arr =GArray.create(js_arr);
85
+
```
86
+
87
+
Importantly, type information is retained i.e. the following will compile:
Accessing data this way is particularly useful if you want to pluck out a few values from a large data structure. However, when you access nested data this way JavaScript `Proxy` objects are created on the fly; which can cause overhead with frequent nested access.
156
+
157
+
If you're performing frequent access, it'll likely be more efficient to convert the data structure to JavaScript objects just the once.
158
+
159
+
You can use the spread operator to create a JavaScript object from a proxy:
Keep in mind that these are _shallow_ copies i.e. only the top level collection has been converted to a JavaScript object/array. Nested Godot collections will remain (as proxies).
178
+
72
179
### StringName
73
180
74
181
`StringName` optimization is completely transparent in javascript. When passing `StringName` parameters, a mapping between `StringName` and `v8::String` will be automatically cached to avoid repeatedly allocation of new `v8::String` objects and Godot `Variant` objects.
0 commit comments