Closed hagabooga closed 3 years ago
This is due to the fact that Godot dictionaries and arrays are passed by reference.
Basically when you call the .select_rows()
function again, the data
values are overwritten since it is the exact same reference.
https://docs.godotengine.org/en/latest/tutorials/scripting/gdscript/gdscript_basics.html#built-in-types
As you mention, You'll need to duplicate the data to fix this. (Possibly you'll also have to set the deep
-value to True)
Since this is Godot's intended behaviour, I don't think anything needs to be fixed per se?
but why does select_rows return the same reference?
For two main reasons:
duplicate()
-function hasn't been properly implemented yet in godot-cpp
, so I can't call it myself in the C++ code 🤷♂️ I would have to use my own (inferior = slower) implementation.select_rows()
-function when you are selecting 1000+ rows (or any larger amount than 2) since you don't have to copy every field by value.Or if you are asking this question in a more 'How is this implemented in C++?' way:
select_rows()
-function returns the query_result
-array which is the internal Array used for all query results and thus is re-used for every query.select_rows returning query_result makes sense now. Thanks for the quick reply.
Spent an hour wondering why my value returned from select_rows was being modified incorrectly and realized if I called select rows again in the same function it changes the previously stored variable or some undefined behavior.
Example:
I don't know whether or not this is intended or I'm missing something but maybe there should be something on the docs about it?
To fix this I need to duplicate data.