Shoutbox

Getting started - 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: Getting started (/showthread.php?tid=86600)

Getting started by Jonte135 on 10-12-2008 at 02:41 PM

I've downloaded the Scripting Documentation and read until "Your first script". What's the next step? It doesn't really explain much more after that ^o)

Thanks :)


RE: Getting started by Matti on 10-18-2008 at 06:57 PM

When you finished reading the Getting Started section, you're ready to pick up an idea and make it a Plus! Live script. :)

This will mean a lot of trial and error, I can assure you that. Think about something you want to try out, then think how you'd convert that idea into code. It really depends on what you want to do, it's impossible to give an all-round solution for each possible idea. Try to come up with something interesting which you might find useful, and then be creative. It may help if you already have some programming experience, if not you might run into difficulties understanding the thinking process of writing a program.

If you ever need help with how to execute a certain idea, don't hesitate to ask here. We'll see if your idea is technologically possible with the current possibilities of the scripting engine and help you with finding a good approach for your code. Just try to avoid asking for completely functioning code - you'll learn much more when you write your code yourself! ;)


RE: Getting started by Jonte135 on 10-18-2008 at 07:03 PM

Ahh ok thanks, well I already have an idea which is a simple bot that will answer on questions etc. For example if someone says "hi" to me it will answer back. How to do that is the problem though :(


RE: Getting started by Matti on 10-18-2008 at 09:28 PM

Well, the idea you have comes with a variety of possible problems. :D

First of all, you'll need to find a way not to respond to your own messages. That means, if you respond on "hi" with "hi there!", you have to avoid responding on "hi there!" too.

Secondly, you'll need a proper way to find the messages you're looking for. You could go the easy way and simply use:

code:
if(Message.indexOf("hi") !== -1) {
but that won't match "Hi" or "HI". Also, you might want to avoid matching "hitch" as well. That's where regular expressions can come in handy, such as:
code:
if(/\bhi\b/\b.test(Message)) {
However, that may already be quite advanced, so maybe you should first learn about those when you plan to do it really good. :)

But your basic concept may look like:
code:
var Match = {
   "hi" => "Hello there! :)",
   "how are you" => "I'm fine, thanks! ;)"
};

function OnEvent_ChatWndReceiveMessage(ChatWnd, Origin, Message, Kind) {
   //1. Check if the message was sent by a contact and not yourself.
   //2. Loop through the Matches with for(var Key in Matches) {}.
   //3. Match the key against the Message.
   //4. If a match was found, send the respond message (Matches[Key]) and return to prevent multiple responses for one message.
}
A good trick to get around the first problem is by using a timer of 1 second when a message is sent by you. That will set a global variable (such as bDoNotRespond) to true. Then, when the timer runs out, you set it back to false. You can now check in the receive message event first if bDoNotRespond is true, and then cancel the timer and return immediately to prevent responding to your own messages. That way, you don't need to use all kinds of workarounds to match Origin against the right contact name. ;) (Think about custom nicknames, StuffPlug's timestamps,...)

Anyway, I'm sure there are a lot of threads here which may help you with this. Good luck! :)
RE: Getting started by Jonte135 on 10-18-2008 at 10:11 PM

Thanks a lot! I have thread that I made, click here, and I will be going from there to make the rest :)