IssueRaiser

Add array unpacking/destructuring to GDScript

### Describe the project you are working on A rhythm game, though more importantly a project where it makes sense for certain functions to return multiple values. ### Describe the problem or limitation you are having in your project I have a number of functions that return 2-3 distinct values, packed into an Array in GDscript. A simple example would be one that returns `[PoolVector2Array positions, PoolRealArray angles]`. Currently, I have two options to unpack that: ```gdscript var result = note.get_points(): var positions = result[0] var angles = result[1] # ... ``` And what I'm currently using where convenient, binding match: ```gdscript match note.get_points(): [var positions, var angles]: # ... ``` Except it's not as convenient as it could be since it introduces new scope and two indent levels. ### Describe the feature / enhancement and how it helps to overcome the problem or limitation Arrays will be able to unpacked on a single line similar to Python or Lua. It will be possible to assign (and sometimes declare) multiple variables on a single line to the inner contents of an array. `a, b, var c = [1, 2, 3]` will set existing vars a to 1, b to 2, new var c to 3. In the case of my earlier specific example, it would become: ```gdscript var positions, var angles = note.get_points() # ... ``` Which saves the visual noise of both workarounds and the scope+indents of the binding match. ### Describe how your proposal will work, with code, pseudo-code, mock-ups, and/

Posted by Birdulon on Jan 17, 2021, 5:04 AM

Tags

Related issues

Raise real-world problems, find people facing the same issue, and discuss solutions.3,000 issues0 comments

github (Other)

Add array unpacking/destructuring to GDScript

BirdulonJan 17, 2021, 5:04 AM

### Describe the project you are working on A rhythm game, though more importantly a project where it makes sense for certain functions to return multiple values. ### Describe the problem or limitation you are having in your project I have a number of functions that return 2-3 distinct values, packed into an Array in GDscript. A simple example would be one that returns `[PoolVector2Array positions, PoolRealArray angles]`. Currently, I have two options to unpack that: ```gdscript var result = note.get_points(): var positions = result[0] var angles = result[1] # ... ``` And what I'm currently using where convenient, binding match: ```gdscript match note.get_points(): [var positions, var angles]: # ... ``` Except it's not as convenient as it could be since it introduces new scope and two indent levels. ### Describe the feature / enhancement and how it helps to overcome the problem or limitation Arrays will be able to unpacked on a single line similar to Python or Lua. It will be possible to assign (and sometimes declare) multiple variables on a single line to the inner contents of an array. `a, b, var c = [1, 2, 3]` will set existing vars a to 1, b to 2, new var c to 3. In the case of my earlier specific example, it would become: ```gdscript var positions, var angles = note.get_points() # ... ``` Which saves the visual noise of both workarounds and the scope+indents of the binding match. ### Describe how your proposal will work, with code, pseudo-code, mock-ups, and/

Comments (0)

No comments yet. Start the discussion.

Comment on this issue