What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » AJAX isn't working

Pages: (2): « First « 1 [ 2 ] Last »
AJAX isn't working
Author: Message:
CookieRevised
Elite Member
*****

Avatar

Posts: 15521
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
RE: RE: RE: AJAX isn't working
quote:
Originally posted by The-Phantom
quote:
Originally posted by CookieRevised
No...
1) nothing will be executed after a return statement
2) when you return the same message, the command will be send to your contact too (as text).
3) in that code you check if the message is _not_ "/ajax-test", it should the opposite.

See the code in my previous post for the proper way.
I still don't get it. If it is the command I need, the if clause is skipped and the handling is performed.
No it is not. the handling of the command (that comment block) is placed after the return statement in your code. Anything after a return statement will not get executed.

And, again, you should NEVER perform a negative check (!= or !==) when you want to check for your command, that is realy not the proper way of doing things and it will cripple other stuff. It is also not logical to do it and it requires more code.

Read the scripting documentation about command handling....

The proper way is:
Javascript code:
function OnEvent_ChatWndSendMessage(ChatWnd, Message) {
    if (Message.substr(0, 10) === "/ajax-test") {
        // your code for the command /ajax-test here
        return "";
    }
}


quote:
Originally posted by The-Phantom
quote:
There are some things you need to know whenyou want to change recieved text.

Biggest thing is that you can never change recieved text to text which is longer than the original.

Second, text you receive also includes your own send messages.

See OnEvent_ChatWndReceiveMessage event.

All this is also explained in the Plus! Scripting documents.

;)
Yes, yes, I know. How could I be able to make some scripts without reading that first?
You would be surprised to know how many people start scripting without properly reading the docs (and then comming here for help) :P Anyways, I posted that because you asked about changing recieved text. Those are the basics to know for doing that. If that is not what you wanted then I misunderstood you. In that case, could you maybe rephrase your question? Or explain in a detailed way what it is that you exactly want to with all of this.


;)

This post was edited on 08-30-2010 at 09:05 AM by CookieRevised.
.-= A 'frrrrrrrituurrr' for Wacky =-.
08-30-2010 09:01 AM
Profile PM Find Quote Report
The-Phantom
New Member
*


Posts: 10
Joined: Aug 2010
O.P. RE: RE: RE: RE: AJAX isn't working
quote:
Originally posted by CookieRevised
No it is not. the handling of the command (that comment block) is placed after the return statement in your code. Anything after a return statement will not get executed.

I thought that a return statement stops the further code from execution only if that return statement is executed? So if return is skipped, it doesn't stop the execution?

quote:
And, again, you should NEVER perform a negative check (!= or !==) when you want to check for your command, that is realy not the proper way of doing things and it will cripple other stuff. It is also not logical to do it and it requires more code.

Okay, I'll note that (even though I don't exactly understand the reasons).

quote:
You would be surprised to know how many people start scripting without properly reading the docs (and then comming here for help) :P Anyways, I posted that because you asked about changing recieved text. Those are the basics to know for doing that. If that is not what you wanted then I misunderstood you. In that case, could you maybe rephrase your question?

;)

Well, I meant that it is impossible to have a message appear as "received" even though I didn't actually receive it.
08-30-2010 09:22 AM
Profile E-Mail PM Find Quote Report
Eljay
Elite Member
*****

Avatar
:O

Posts: 2949
Reputation: 77
30 / Male / Flag
Joined: May 2004
RE: AJAX isn't working
The way that your code is structured is fine, obviously return will not be executed and execution of that function will continue so I don't know what Cookie is on about there :P (I actually prefer coding like that, much easier to read and debug without everything being needlessly nested).

I'm not sure exactly how things work internally, but surely just returning the original message is the same as not returning anything? (If not, it's very illogical but I can see how that might break things). The way you had it originally (return "") was wrong and will stop the message being sent completely, but returning the original message SHOULD be fine.
08-30-2010 09:41 AM
Profile PM Find Quote Report
CookieRevised
Elite Member
*****

Avatar

Posts: 15521
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
RE: AJAX isn't working
quote:
Originally posted by Eljay
The way that your code is structured is fine, obviously return will not be executed and execution of that function will continue so I don't know what Cookie is on about there :P (I actually prefer coding like that, much easier to read and debug without everything being needlessly nested).
After you posted I looked at his proposed code again (several times)... Only after like 5 times looking at those few lines of coding, I realized I made a mistake.

But this was exactly because he did NOT nested the if structure between brackets { }. So reading and debugging made easier if you don't nest stuff? I realy dont think so... It's more confusing and mistakes happen more quickly, especially when you split things out on several lines. (and reading other scripting topics, such mistakes happen all the time)... edit: see again here (and I can probably keep on updating with more links regulary)...

But thanks for pointing out my mistake. (y)

So, yes, using a negative check like that and returning the _original_ message will work, but besides I think it is not logic to do, it does make code more confusing and execution slower (you should not notice it though)...

Furthermore, the moment you want to make your check a bit better (eg: taking in account the casing of the command, and other tid bits), use regular expressions, want to use more than one command, or want to check on other things too (eg: who the contact is or whatever), your code quickly becomes more confusing and harder to follow if you use a negative check. And you'll find that you'll quickly revert to a positive check in such cases anyways for such stuff.

quote:
Originally posted by The-Phantom
quote:
You would be surprised to know how many people start scripting without properly reading the docs (and then comming here for help) :P Anyways, I posted that because you asked about changing recieved text. Those are the basics to know for doing that. If that is not what you wanted then I misunderstood you. In that case, could you maybe rephrase your question?

;)
Well, I meant that it is impossible to have a message appear as "received" even though I didn't actually receive it.
So you want to show a kind of status message? Then this doesn't have much to do with changing recieving text. You actually want to _add_ text, if I'm not mistaken.

You indeed can't directly add text to the history window, but you can use DisplayInfoMessage to show a status message in the chat window. Or you can use toasts.

This post was edited on 09-10-2010 at 11:22 PM by CookieRevised.
.-= A 'frrrrrrrituurrr' for Wacky =-.
08-30-2010 10:12 AM
Profile PM Find Quote Report
Eljay
Elite Member
*****

Avatar
:O

Posts: 2949
Reputation: 77
30 / Male / Flag
Joined: May 2004
RE: AJAX isn't working
quote:
Originally posted by CookieRevised
But this was exactly because he did not nested the IF structure between { }. So reading and debugging made easier if you don't nest stuff? I dont think so... it's more confusing and mistakes happen more quickly, especially when you split things out on several lines. (and reading other scripting topics, such mistakes happen all the time)...

I agree it can be harder to read if you omit the braces, but what I meant was, for example, the difference between these two code blocks:

Javascript code:
if(functionA()) {
    if(functionB()) {
        // do something
    }
    else {
        // handle error b
    }
}
else {
    // handle error a
}
 
// ==========
 
if(!functionA()) {
    // handle error a
    return;
}
if(!functionB()) {
    // handle error b
    return;
}
 
// do something


It keeps everything together nicely imo, with the error handling right next to the error. Obviously it might not always be applicable, and everything is open to argument :P

[/off-topic]
08-30-2010 10:35 AM
Profile PM Find Quote Report
Pages: (2): « First « 1 [ 2 ] Last »
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On