0 votes

In my code, I am cycling through an array comparing the current one with the next one but sometimes there is an array within that array so it comes up with an error saying I can't compare an integer with an array so I used this typeof(tile_positions[timeNo + 1]) != TYPE_ARRAY so it does not compare if it is not an array but this is apparently always true so it ends up never comparing, so is there a TYPEARRAYARRAY or something else I could use to achieve the same result.

in Engine by (42 points)

Do you learn about Arrays this https://javascript.info/array

1 Answer

0 votes
Best answer

While you don't show much code, this works as expected for me:

func _ready():
    var abc = [1, 2, 3, 4, ["a", "b"]]
    print(typeof(abc))
    print(typeof(abc[2]))
    print(typeof(abc[4]))
  • 1st print returns 19 for the entire array (TYPE_ARRAY)
  • 2nd print returns 2 for the array value 3 (TYPE_INT)
  • 3rd print returns 19 for the subarray value (TYPE_ARRAY)

Does that point you in the right direction?

If not, please post more code (including the array contents and the code that processes it).

by (13,674 points)
selected by

Thanks alot I just replaced TYPE_ARRAY with 19 and that worked

That sounds really suspicious. TYPE_ARRAY is just an enum representation of the value 19. So, they should be absolutely interchangeable. And, with that in mind, I'd highly recommend that you use TYPE_ARRAY instead of the value 19.

So called magic numbers are never good to have floating around in code. If you look at that code 6 months from now, you'll probably ask yourself what 19 means. However, if you instead see TYPE_ARRAY there, it'll probably make sense immediately.

Really, I think you must have done more than changed the TYPE_ARRAY reference to 19. Whatever those other changes were must have been the real fix. Otherwise, it doesn't make sense to me.

Regardless, I'm glad you have it working now.

That's odd because whenever I did print(typeof(tilepositions[timeNo]) == TYPEARRAY) it always returned true even on the integers sections of the array that's why it didn't work but when I switched it to 19 in the code it started to work so I'm thinking it got confused somehow in what it was trying to check.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.