Godot version:
3.2.2.stable.official
Issue description:
So I declared a variable called array which takes it's elements from another array that is stored in a json file. And I want to see if a certain value is inside the array. The loop I've written to traverse the array is returning true whereas the function has is returning false. I wonder if this problem is related to the engine or because of something I'm missing.
Steps to reproduce:
Does the JSON contain 300 as a number or as a string? The print handler won't make a difference between those, so be careful.
PS: JSON doesn't distinguish integer numbers from floating-point numbers.
It contains it as a number
@KutayGuler Could you upload a minimal reproduction project, please?
@Calinou Sure, I will upload it in a moment.
@Calinou here it is
As Calinou said JSON doesn't distinguish integers from floats. In your example you are trying to check if the array contains 300 (integer). But array actually contains 300.0 (floting-point number).
array.has(300.0) <- this will work
array.has(300) <- this won't work
One thing that I have noticed is when using in keyword you can actually use integers:
300 in array <- this will work
300.0 in array <- this will also work
Indeed, this is intended behavior. The array contains 300.0, not 300.
Changing the behavior in GDScript's array has method is not going to happen (because GDScript does have integers so this distinction makes sense), but maybe parse_json could have a boolean setting to treat whole numbers as integers?
Thanks for the explanations :) @Calinou @HazmatDemon @aaronfranke
Most helpful comment
Indeed, this is intended behavior. The array contains
300.0, not300.Changing the behavior in GDScript's array
hasmethod is not going to happen (because GDScript does have integers so this distinction makes sense), but maybeparse_jsoncould have a boolean setting to treat whole numbers as integers?