Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers AppGameKit Corner / [SOLVED] Search in Array of Type

Author
Message
bembulak
User Offline
Joined: 5th Mar 2022
Location:
Posted: 15th Apr 2022 22:09
Hi all,

can anyone explain how I have to use custom Types with Arrays?

I could manage to define my own Type, make variables of it and even add them to an Array.

But I can't figure out how to search in the Array for one of the types. It's not that I can't find anything (getting -1 as result), but I get an error, that I can't explain.



Thank you!
Cheers,

> not a native speaker | AppGameKit Classic T1+T2 | AppGameKit Studio T1 + T2

The author of this post has marked a post as an answer.

Go to answer

hendron
6
Years of Service
User Offline
Joined: 20th Dec 2015
Location:
Posted: 16th Apr 2022 01:09
This post has been marked by the post author as the answer.
You actually can't search arrays of User Defined Types using a type instance as the search field. Whenever you sort an array of UDTs, the array is sorted using the first field of the UDT. In your case, the array is being sorted by the x field whenever you use insertSorted(). Usually if I need to have a sorted array of UDT's I will make the first field some sort of ID field, whether it be an integer or a string.

bembulak
User Offline
Joined: 5th Mar 2022
Location:
Posted: 16th Apr 2022 10:18
Thank you hendron.
The hint with the first field of type is also mentioned in the documentation, but I could not make any sense of it, especially when it comes to the find-function. It's just briefly explained (and IMHO needs an update/extension/example).

Your example fills the blanks for me.
Cheers,

> not a native speaker | AppGameKit Classic T1+T2 | AppGameKit Studio T1 + T2
adambiser
AGK Developer
7
Years of Service
User Offline
Joined: 16th Sep 2015
Location: US
Posted: 17th Apr 2022 06:27
I'll also mention that arrays have an .indexof function that works on unsorted arrays. However, it has a bug in it. Hopefully they will fix it.

Login to post a reply

Server time is: 2022-10-03 04:07:29
Your offset time is: 2022-10-03 04:07:29