YoYoGames / GameMaker-Bugs

Public tracking for GameMaker bugs
24 stars 8 forks source link

In-Game: Various array_...() functions could return the new array size instead of returning no value #7523

Open gnysek opened 1 month ago

gnysek commented 1 month ago

Is your feature request related to a problem?

I'm sometimes in situation where after adding struct values using array_push, I need to change some properties depending on user progress. I could of course change structs to already include it, but I've also came with an idea, that array_push would return current size of such array. So, instead of doing:

array_push(a, { ... struct });
a[array_length(a)-1].some_property = some_value;

I could do

var _size = array_push(a, { ... struct });
a[_size-1].some_property = some_value;

Describe the solution you'd like

array_push() could return new array size. Now it returns nothing.

Describe alternatives you've considered

I can of course do:

array_push(a, { ... struct });
var _size = array_length(a);
a[_size-1].some_property = some_value;

But this means 3 lines of code instead 2 :)

Additional context

This is QoL change, that would save writing few characters :)

Edit: array_insert and array_delete could also get such change.

backYard321 commented 1 month ago

this makes sense! i can also imagine this for array_insert()

Totobal5 commented 1 month ago

Yes please add this

KormexGit commented 1 month ago

Adding it for array_delete as well could also make sense, since that has no return either

backYard321 commented 1 month ago

I've noticed that array_reverse_ext() returns a real, whereas array_shuffle_ext() does NOT, despite the fact that both keep the same number of valid array elements (as far as I understand).

IMO, array_shuffle_ext() should also return a real, to make it consistent with the other "extended array functions" (apart from array_create_ext(), which needs to return an array)