<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Compliments module stops cycling compliments]]></title><description><![CDATA[<p dir="auto">Alright, my problem is that over a short period of time (5-10 updates) the default Compliments module will stop changing compliments. It simply displays the same compliment endlessly.</p>
<p dir="auto">I decided to dig into the issue. I will spare you the troubleshooting process, but I found out that the Compliments module will append the ‘anytime’ compliment to the end of the <em>existing</em>  <code>compliments</code> array. So the <code>compliments</code> array gets longer every time it is updated.</p>
<p dir="auto">The ‘anytime’ compliments are appended to the end of the <code>compliments</code> array,  which grows the array indefinitely. The random compliment function works as intended, but if the <code>compliments</code> array has 10 ‘anytime’ compliments and 3 ‘afternoon’ compliments, there’s a high chance that a ‘anytime’ compliment will be chosen. The odds that an ‘anytime’ compliment will be chosen goes up every update.</p>
<p dir="auto">Specifically, I’ve found the issue to occur right <a href="https://github.com/MichMich/MagicMirror/blob/master/modules/default/compliments/compliments.js#L101" target="_blank" rel="noopener noreferrer nofollow ugc">when the compliments array is filled with compliments</a>. What happens (in my case) is that the compliments that get added to the <code>compliments</code> array <em>already includes the ‘anytime’ compliments</em>. Then, <a href="https://github.com/MichMich/MagicMirror/blob/master/modules/default/compliments/compliments.js#L117" target="_blank" rel="noopener noreferrer nofollow ugc">a few lines later, the ‘anytime’ compliments are appended to the end of the now-filled compliments array</a>.</p>
<p dir="auto">Why this happens is not clear to me at all. Looking at the code, the ‘afternoon’ compliments should be added to the compliments array, then the anytime compliments should be appended. The compliments array is initially set to null, and that works, but for some reason, when the ‘afternoon’ compliments are assigned to the compliments array, the anytime compliments are included. Again, this does not make sense. (It shouldn’t be doing that)</p>
<p dir="auto">To illustrate what I am talking about, add the following lines <a href="https://github.com/MichMich/MagicMirror/blob/master/modules/default/compliments/compliments.js#L116" target="_blank" rel="noopener noreferrer nofollow ugc">right after the if-then-else loop that sets the compliments array</a>.</p>
<pre><code>Log.info("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
Log.info("COMPLIMENTS FROM FILE (afternoon):  " + this.config.compliments.afternoon);
Log.info("~~~~");
Log.info("COMPLIMENTS STORED IN COMPLIMENTS VARIABLE " + compliments);
</code></pre>
<p dir="auto">Make sure you change ‘afternoon’ to whatever time of day it currently is. Then run `npm start dev’ and watch the console on the right side of the screen.</p>
<p dir="auto">What I saw (in the dev console) was that <code>this.config.compliments.afternoon</code> displayed the correct compliments defined by the defaults or whatever external file I specified. However, the <code>compliments</code> array would <em>somehow</em> have the ‘anytime’ compliments in it. Every time the program updated the <code>compliments</code> array, there would be one more set of ‘anytime’ compliments at the end.</p>
<p dir="auto">Using the same method of displaying the array at different points of program, I found out that the <code>compliments</code> array <em>is</em> being set to null initially. I can’t for the life of me figure out why the ‘anytime’ compliments would get in there.</p>
<p dir="auto">To eliminate even more variables, I renamed my <code>~/MagicMirror</code> directory and downloaded and installed a new one. I put the lines above in the <code>compliments.js</code> file and I observed the same behavior.</p>
<p dir="auto">Hopefully, I explained this issue well enough that other people can understand. I also hope that this is a simple fix or mistake on my end. I would be glad to provide any extra info that might be needed. Thank you for any assistance.</p>
]]></description><link>https://forum.magicmirror.builders/topic/2381/compliments-module-stops-cycling-compliments</link><generator>RSS for Node</generator><lastBuildDate>Sat, 18 Apr 2026 09:59:33 GMT</lastBuildDate><atom:link href="https://forum.magicmirror.builders/topic/2381.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 22 Apr 2017 06:46:33 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Compliments module stops cycling compliments on Sat, 22 Apr 2017 21:13:45 GMT]]></title><description><![CDATA[<p dir="auto">Alright I will switch to the develop branch.</p>
<p dir="auto">Very interesting. I’m glad the issue got resolved!</p>
]]></description><link>https://forum.magicmirror.builders/post/20196</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/20196</guid><dc:creator><![CDATA[maxfarrior]]></dc:creator><pubDate>Sat, 22 Apr 2017 21:13:45 GMT</pubDate></item><item><title><![CDATA[Reply to Compliments module stops cycling compliments on Sat, 22 Apr 2017 18:08:03 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/maxfarrior" aria-label="Profile: maxfarrior">@<bdi>maxfarrior</bdi></a> It was merged in develop branch about an hour ago.</p>
<p dir="auto">You can switch to develop branch by <code>git checkout develop</code> in the MagicMirror directory.</p>
<p dir="auto">I guess most people only use the standard compliments morning, afternoon and evening without anytime and weather, where the error not occurs.</p>
]]></description><link>https://forum.magicmirror.builders/post/20189</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/20189</guid><dc:creator><![CDATA[strawberry 3.141]]></dc:creator><pubDate>Sat, 22 Apr 2017 18:08:03 GMT</pubDate></item><item><title><![CDATA[Reply to Compliments module stops cycling compliments on Sat, 22 Apr 2017 18:05:12 GMT]]></title><description><![CDATA[<p dir="auto">Awesome! Your explanation makes sense and I’m glad you were able to understand what I was saying and then make a fix.</p>
<p dir="auto">First, can I go ahead and copy your fix into my code? I don’t see why not, but I thought I’d ask.</p>
<p dir="auto">Second, am I really the first person to notice this? I feel like the behavior is pretty noticeable.</p>
]]></description><link>https://forum.magicmirror.builders/post/20188</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/20188</guid><dc:creator><![CDATA[maxfarrior]]></dc:creator><pubDate>Sat, 22 Apr 2017 18:05:12 GMT</pubDate></item><item><title><![CDATA[Reply to Compliments module stops cycling compliments on Sat, 22 Apr 2017 09:52:22 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/maxfarrior" aria-label="Profile: maxfarrior">@<bdi>maxfarrior</bdi></a> you’re right that is a bug.</p>
<p dir="auto">The way javascript handles variables are usually call by value, but for objects (this includes arrays) it is call by reference.</p>
<p dir="auto">So what happens in <a href="https://github.com/MichMich/MagicMirror/blob/90f60f95f77236c2b58e34350781a400fa3ec411/modules/default/compliments/compliments.js#L104" target="_blank" rel="noopener noreferrer nofollow ugc">line 104</a> is the following: The variable compliments doesn’t get cloned, so that the values are equal. What happens is they are the same array and point to the same reference to the memory. That means in the following lines not only compliments get changed, also <code>this.config.compliments.afternoon</code> gets changed.</p>
<p dir="auto">So in the beginning your config looks like that</p>
<pre><code>config: {
  compliments: {
    afternoon: ["I'm the only one here"],
    anytime: ["I'm getting repeated"]
  }
}
</code></pre>
<p dir="auto">after the first iteration it looks like this</p>
<pre><code>config: {
  compliments: {
    afternoon: ["I'm the only one here", "I'm getting repeated"],
    anytime: ["I'm getting repeated"]
  }
}
</code></pre>
<p dir="auto">after the second</p>
<pre><code>config: {
  compliments: {
    afternoon: ["I'm the only one here", "I'm getting repeated", "I'm getting repeated"],
    anytime: ["I'm getting repeated"]
  }
}
</code></pre>
<p dir="auto">and so on …</p>
<p dir="auto">So to fix that, we have to create a real clone not only a pseudo one.</p>
<p dir="auto">I already created a bugfix for that <a href="https://github.com/MichMich/MagicMirror/pull/867" target="_blank" rel="noopener noreferrer nofollow ugc">here</a></p>
]]></description><link>https://forum.magicmirror.builders/post/20158</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/20158</guid><dc:creator><![CDATA[strawberry 3.141]]></dc:creator><pubDate>Sat, 22 Apr 2017 09:52:22 GMT</pubDate></item></channel></rss>