Shoutbox

Display Picture switches back - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: Display Picture switches back (/showthread.php?tid=88883)

Display Picture switches back by Genesis Genome on 02-02-2009 at 12:56 AM

the flow of events goes like this:

Display Picture is changed
five second timer is triggered
after five seconds, the Display Picture is changed back to the original

I have had no problems getting this to work.
HOWEVER, occasionally a few seconds after it switches back to the original, it will switch again, back to the one it switched to.
ie, image A becomes image B for 5 seconds, turns back to image A but then after a few seconds goes back to image B and stays there until changed.

The fact that it only does this sometimes and not all the time leads me to think that it may not be a problem on my side but lag between the client and server and the server is switching it back, but I'm really not sure.

Does anyone know the true cause of this problem and has anyone found a (reasonable) work around for it?


RE: Display Picture switches back by matty on 02-02-2009 at 02:42 AM

Post your code.

[code=js][/code]


RE: Display Picture switches back by Genesis Genome on 02-02-2009 at 10:25 AM

js code:
var DelayLength = 5000;
var FolderWithEmotes = "";
var DParray = new Array(
    "",
    "1.gif",
    "2.gif",
    "3.gif"
);
String.prototype.toArray = function(){
    return this.split(' ');
}

function OnEvent_Timer(timerID)
{
    if(timerID == "DPdelay")
    {
        Messenger.MyDisplayPicture = DParray[0];
    }
}

function OnEvent_ChatWndSendMessage(ChatWnd, Message)
{
    var index = 0;
    var msgwords = Message.toArray();
    for (var i=0;i<msgwords.length;i++){

        if(msgwords[i] == "blah"){
            index = 1;
        }
    }   

    if (index > 0) {
        DParray[0] = Messenger.MyDisplayPicture;
        Messenger.MyDisplayPicture = FolderWithEmotes + DParray[index];
        MsgPlus.AddTimer("DPdelay", DelayLength)
    }
    index = 0;
}

basically it scans a message for a word, and if its there it sets your DP to a specific image for a few seconds and then switches back.
And it does that, its just that sometimes it'll switch back to the temporary image.
RE: Display Picture switches back by CookieRevised on 02-02-2009 at 02:59 PM

Is the the complete code? If so, some potential problems will arise. This is because you're using timers. And with timers you need to be extra carefull... always. And cope with a lot more situations than just the obvious ones.

For starters, you don't cancel the timer when some other user logs in to Messenger. It isn't even cancelled when you log out. This will produce errors and at the least unexpected behaviour when such events occur. Remember that timers are not user specific and that scripts start to run the second you start Messenger. So they are running even before you log in and continue to run until you completely quit the Messenger application; they don't stop running when you simply log out. So this is also true for timers. All this is way too often forgotten in extremely many scripts (including many in the official script DB), making them all not work properly!!

Second, whenever a message is send before the timer delay has passed, you will get the exact behaviour as you described as being the problem. This is because the second time the ChatWndSendMessage event is fired the 'original' DP in the array (at index 0) is overwritten with the temporary one from the previous event.

So, what you must do:
1) add the event for when the user signs out. In that event, cancel the timer which might still be running.

2) Add a check to see if the global array contains an 'original' DP at index 0. if so, do not write the current display picture to index 0. This because when this occurs, the current showing DP is not the user's original one but a temporary one from a previous 'word to DP' event.

3) In the timer event, after the original DP is set back, you also need to clear out index 0 of the global array to accomodate proper workings of point 2.


Note: there are limits in how often you can change your DP in a certain timespan. This means that scripts like this will always have some potential problems and limits and might not always work properly; there will always be times and situations when your original DP can not be set back.


Note for point 1: you can make it a bit more complicated in such a way that the timer isn't cancelled but continues to run when a user logs out. But, in that case you need to make the timer user specific (the name can contain the user ID to make it user specific) and check if the same user is still logged in before setting the DP back. This makes that the script will support multiple users and that it can cope with sudden unexpected disconnections and reconnections of Messenger. Ofcourse, you would also need an array per user, or in other words a two dimensional array containing the user's ID and the corresponding original DP, (and the index of the 'Word'-DP for that user).

;)


RE: Display Picture switches back by Genesis Genome on 02-02-2009 at 03:51 PM

According to the documentation, the timer is only created once when called and is destroyed after completion, so I don't understand your problem with the timer never going away.
It is created only when a matching word is found, and deletes itself 5 seconds later.

and the problem with changing dps to fast and overwriting the original I am well aware of, however even if I don't say anything at all, it will still sometimes switch back. so I know this is not the problem either.


RE: Display Picture switches back by Matti on 02-02-2009 at 04:03 PM

quote:
Originally posted by Genesis Genome
According to the documentation, the timer is only created once when called and is destroyed after completion, so I don't understand your problem with the timer never going away.
It is created only when a matching word is found, and deletes itself 5 seconds later.
The problem is that when the timer is started, the user could sign out and optionally sign back in on another account and when the timer is finished, the code gets executed on the wrong account. Therefore, it is wise to cancel your timers on sign out or, as mentioned by Cookie's footnote, make your timer ID contain user-specific details to determine the user and/or picture index.
quote:
Originally posted by Genesis Genome
and the problem with changing dps to fast and overwriting the original I am well aware of, however even if I don't say anything at all, it will still sometimes switch back. so I know this is not the problem either.
Well, in my opinion you shouldn't allow it to change more than 5 times per minute, since every time you change it, it has to be uploaded to the Messenger servers. Seeing that you already change it twice with a five second interval, you might run into some troubles. For example, you could add a timer after your "DPDelay" timer was executed to prevent changes for the next 20 seconds or so using some kind of global variable.
RE: Display Picture switches back by Genesis Genome on 02-02-2009 at 04:10 PM

Well, considering the chances of me sending a message that triggers the timer,logging out and logging into a second account I don't have, all within 5 seconds, the issue isn't on the top of my todo list.
but adding a second timer to prevent consecutive changes is a good idea, I'll have a play with that. thanks.
It seems like its just the server rejecting my changes after all, which is what I always suspected.


RE: Display Picture switches back by Matti on 02-02-2009 at 04:14 PM

quote:
Originally posted by Genesis Genome
It seems like its just the server rejecting my changes after all, which is what I always suspected.
Correct. When you update it too much, it'll simply ignore your requests or even send you annoying error pop-ups. If the servers didn't do that, there wouldn't be any problem - but they do. :P
RE: RE: Display Picture switches back by CookieRevised on 02-02-2009 at 04:29 PM

quote:
Originally posted by Genesis Genome
According to the documentation, the timer is only created once when called and is destroyed after completion, so I don't understand your problem with the timer never going away.
It is created only when a matching word is found, and deletes itself 5 seconds later.
I never said the timer will never go away though. I said the timer will still be running when you log off (for whatever reason, it doesn't need to be explicitly be done by you) if the delay hasn't passed yet.

Also, a lot of stuff can happen in those 5 seconds. Stuff which you don't always have control over. Thus including but not limited to the user logging out _and_ the user sending another message.

Note that by logging out I mean eveything that involves the user logging out, thus this also means sudden and quick disconnections and reconnections and other network hickups which might/will occur.

This is something you _must_ take in account when working with timers or you _will_ have problems.

quote:
Originally posted by Genesis Genome
and the problem with changing dps to fast and overwriting the original I am well aware of, however even if I don't say anything at all, it will still sometimes switch back. so I know this is not the problem either.
Sorry, but it IS one of the problems you WILL encounter. Maybe not now, but later on for sure.

If it happens when you don't say anything at all then that can be caused by ANOTHER problem which was also explained before and which you apparently are aware of: there is a limit on how many times in a certain amount of time you can change the DP.

Then there is also yet ANOTHER problem which involves roaming. This might occur if you have selected the option "Always keep my DP the same nomatter where I sign in". The servers might not be able to update the DP serverside quickly enough (because of the limit) and detect that there was a DP change and thus send the one they do have back (which was actually your temporary one).

quote:
Originally posted by Genesis Genome
Well, considering the chances of me sending a message that triggers the timer,logging out and logging into a second account I don't have, all within 5 seconds, the issue isn't on the top of my todo list.
Which should be though! There are a lot more situations than you explicitly logging in and out in 5 seconds time. Moreover, the fixes are extremely basic, small and very easy. Not some complex stuff you need to take your time for to implement.

quote:
Originally posted by Genesis Genome
It seems like its just the server rejecting my changes after all, which is what I always suspected.
Together with the rest of the stuff which was explained. It is not just the server rejecting your changes.

I'm sorry to sound a bit grumpy here, but you came here seeking info/advise/help. We gave the exact info you needed and I gave the exact steps which you must do to fix everything there is to fix for as far as you can fix it (you can't fix the problem of the DP change limit as that is serverside). Besides, they are only a few lines of codes (like 4 lines maybe at the most), nothing complex at all.

Simply ignoring these simple but mandatory recommendations to make such script bug free as much as you can, and suggesting that the fixes we suggest are not important, or that we may even be wrong maybe, seems a bit strange to me when you come here to seek some help or advise (and a waste of time from the helpers too if you simply ignore their comments).

Nice idea for a script though...

But as said before also: such scripts will unfortunatly never be able to work properly because of the said limitations. But that does not mean you shouldn't fix the potential problems you already have now, with or without that serverside limitation.

So, adding another timer will NOT fix those other problems I talked about. In fact, it will make things worse and more complex (but not impossible) to cope with. Your choice of course...


;)
RE: Display Picture switches back by Genesis Genome on 02-02-2009 at 05:17 PM

Woh, I didn't mean to get you so riled up.
I know the script isn't perfect, and I know that the timer cancelling is important and should be there to reduce problems further down the road, but the reason I pushed these aside is because they were not relevant to my original question of "why does it switch back" (the answer being the server refuses to handle multiple quick changes)
I'm grateful of the help you've given me and all and I have fixed up these problems already.
Thanks again,
-Gen


RE: RE: Display Picture switches back by CookieRevised on 02-02-2009 at 05:43 PM

quote:
Originally posted by Genesis Genome
Woh, I didn't mean to get you so riled up.
never mind, I do that sometimes, my apologies...

quote:
Originally posted by Genesis Genome
I know the script isn't perfect, and I know that the timer cancelling is important and should be there to reduce problems further down the road, but the reason I pushed these aside is because they were not relevant to my original question of "why does it switch back" (the answer being the server refuses to handle multiple quick changes)
...or you sending multiple messages within 5 seconds... :p

quote:
Originally posted by Genesis Genome
I'm grateful of the help you've given me and all and I have fixed up these problems already.
Thanks again,
-Gen
no worries ;)