• Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

SOLVED Number of symbols in array

I have about 200 seperate characters in an array with duplicates, I want to work out the number of characters in the array excluding duplicates. How would I do so?

Example
Lets say the array was:

[A,B,A,C,B,C]

I'd only count the first A the first B and the first C meaning the result would be 3

Thank you for the help!
 
Last edited:

FrostyCat

Member
GML:
var i, seenChars, currentChar, uniqueN;
seenChars = ds_map_create();
uniqueN = 0;
for (i = 0; i < 6; i += 1) {
    currentChar = arr[i];
    if (!ds_map_exists(seenChars, currentChar)) {
        ds_map_add(seenChars, currentChar, true);
        uniqueN += 1;
    }
}
ds_map_destroy(seenChars);
/* Use uniqueN here */
 
GML:
var i, seenChars, currentChar, uniqueN;
seenChars = ds_map_create();
uniqueN = 0;
for (i = 0; i < 6; i += 1) {
    currentChar = arr[i];
    if (!ds_map_exists(seenChars, currentChar)) {
        ds_map_add(seenChars, currentChar, true);
        uniqueN += 1;
    }
}
ds_map_destroy(seenChars);
/* Use uniqueN here */
Thank you so much!
 
Top