W
William Roberts
Guest
I can't seem to find a function that exists in GMS to remove duplicates from an array or a way to build an array but not add if the entity already exists. So, I decided to write a small script that would remove duplicates when called, but it doesn't seem to work either. Does anyone else have experience with this issue?
I tried to apply my script on a more simplistic level with a string to help understand my logic. The same process would apply is removing duplicate letters from a word. For this script, I'd like to take the word "test" and have it return the letters "tes" (since the "t" is a duplicate). Thanks for the help in advance.
(this code doesn't work as expected)... the results of this is "teessss"
I tried to apply my script on a more simplistic level with a string to help understand my logic. The same process would apply is removing duplicate letters from a word. For this script, I'd like to take the word "test" and have it return the letters "tes" (since the "t" is a duplicate). Thanks for the help in advance.
Code:
var letters = "";
var word = "test";
var i, j;
for (i = 0; i < string_length(word); i++) {
var tmpLtr = string_char_at(word, i);
if (string_length(letters) == 0) {
letters += tmpLtr;
}
if (string_length(letters) > 0) {
for (j = 0; j < string_length(letters); j++) {
if ( tmpLtr != string_char_at(letters, j) ) {
letters += tmpLtr;
}
}
}
}
return letters;