Homey Community Forum

Comparing variables in Homeyscript for duplicates

I am trying to compare better logic variables in homeyscript. The reason is to find duplicate variables. My variables are called RadioDay1, RadioDay2 … RadioDay14.

The variables look like this http://192.168.178.2:5005/woonkamer/favorite/Deep House Ibiza

Or filled with the text No Radio Station

Or filled with the text Playlist1, Playlist2 or Playlist3

I compare the variables like this;
Var n = RadioDay1.localeCompare(RadioDay2)
When n = 0, there is a duplicate variable.

This works ok, but three of the variables have a different input. The input is instead of e.g http://192.168.178.2:5005/woonkamer/favorite/Deep House Ibiza filled with Playlist1, Playlist2 and Playlist3.

When i try this;
Var n = RadioDay1.localeCompare(RadioDay2)
If(n = 0 && RadioDay2 != ‘No Radio Station’ && RadioDay3. != ‘No RadioStation’ || RadioDay1.includes(‘Playlist’) === RadioDay3.includes(‘Playlist’))

It always find a duplicate. When i remove the part RadioDay1.includes(‘Playlist’) === RadioDay3.includes(‘Playlist’)) it works and only find real duplicates. So the problem occurs when i try to find variables with the content Playlist

Anyone a idea what i am doing wrong?

You’re using n = 0 (assignment) instead of n == 0 (comparison).

And possibly you need to group the comparisons using parentheses.

1 Like

Oh🙀 Yes is is the most common mistake within js. And i made it also🙃Will try it, also with parentheses

Edit: tried this but still doesn’t work;
Var n = RadioDay1.localeCompare(RadioDay2)
If((n == 0 && RadioDay2 != ‘No Radio Station’ && RadioDay3. != ‘No RadioStation’ ) || (RadioDay1.includes(‘Playlist’) === RadioDay2.includes(‘Playlist’))

What should this do? A comparison seems strange here.

RadioDay3 was a typing error, should be RadioDay2.

But it doesn’t work.

When RadioDay1 is filled with Playlist3 and RadioDay2 is filled with Playlist1 it should consider that they are duplicates. In the end when there are duplicates the only thing the program does is placing another variable between the duplicates. That way do not get two the same radio stations in a row or two (different) playlists in a row