godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
91.41k stars 21.26k forks source link

Visual Script function which returns Constant (Array) - returns reference, but not value. #49076

Open idchlife opened 3 years ago

idchlife commented 3 years ago

Godot version:

3.3.2

OS/device including version:

macOS

Issue description:

Happened: confusion as to why constant array from another function is being saved in the memory and reused.

Expected: using UNNAMED constants inside functions to utilize their function-lifetime-values, help creating decoupled values from variables for reuse in another functions.

Example: function which returns names of node children and uses Constant with empty array. Those names shuffled and used in another function to show random strings in the interface. Right now the problem is that every time first function called - it will be populated with more and more children names, affecting function logic "give me children names for this one node". Workaround - Constant -> Array.duplicate() right away, which is a problem since Visual Script becomes more hard to read and understand the point of this particular action, especially for non programmers.

изображение

Steps to reproduce: 1) Create function which returns constant with empty array 2) Append elements into array inside another function 3) Print changes to array each time 4) See that function that returns constant returns REFERENCE to constant, but not VALUE. And this unnamed constant from first function is somehow somewhere saved and used every time another function gets it.

Minimal reproduction project:

Just start the scene and see the logs:

poolvector2arrayrepro.zip

Gallilus commented 3 years ago

I do not think it is a error. I have tried to give more clarification in project and image. The project also has GDscript examples showing the same result using modify_array2() that print "append_c" image poolvector2arrayrepro.zip

idchlife commented 3 years ago

@DavidCambre my issue is that Constant node does not have any name, while in GDScript const is used with a particular name. I don't expect "nameless constant" to be used as reference, because I don't see it in Visual Script.

This is very misleading imo.

I expect such behaviour with node like "Global Custom Constant" or something like that.

P.S. I'm generally against using Expression nodes because my friends and colleagues is not that familiar with programming, but they are using Visual Script actively (hence why I create so many issues for Visual Script).

But I suspect you used them just for an example 🤷

Gallilus commented 3 years ago

Is that not just Text based coding vs visual based coding? If you do not need to reference the data point in multiple places, its a box that holds data. seems ok to me.

PS: Id don't like Expression either its to big for one.

idchlife commented 3 years ago

@DavidCambre it maybe actually. Developers of Godot to decide of course.

I personally was confused because of unnamed constant node. I thought - it has no name but value - it allows to create decoupled value and use it once in the function scope, that's it.

Turned out it does opposite.

Who knows, maybe this IS a bug?