What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » First script testing

First script testing
Author: Message:
snazzpompey
New Member
*


Posts: 1
Joined: Mar 2008
O.P. First script testing
thought creating a list of random things to ponder would be a laugh try it out with the attatchments works 100%

.plsc File Attachment: TTP.plsc (3.5 KB)
This file has been downloaded 117 time(s).
03-02-2008 05:46 PM
Profile E-Mail PM Find Quote Report
Spunky
Former Super Mod
*****

Avatar

Posts: 3658
Reputation: 61
36 / Male / Flag
Joined: Aug 2006
RE: First script testing
Not bad, I would suggest adding the command to the script commands window though (see documentation).

I would also use another method of detecting commands in messages (Search for CookieRevised's post on detecting commands as it uses a RegExp and allows you to grab paramaters as well)

You also have 62 array entries, but the random number generator goes upto 65 meaning you will get errors every so often

Overwise this is quite a good script even if I have heard some of them before. Probably better than the first thing I posted (Whatever it was :s)

* Spunky goes to find first code posted on forum
<Eljay> "Problems encountered: shit blew up" :zippy:
03-02-2008 05:52 PM
Profile PM Find Quote Report
Jesus
Scripting Contest Winner
****

Avatar
Koffie, my cat ;)

Posts: 623
Reputation: 15
38 / Male / Flag
Joined: Jul 2005
RE: First script testing
quote:
Originally posted by SpunkyLoveMuff

You also have 62 61 array entries, but the random number generator goes upto 65 meaning you will get errors every so often
0 is not used.

This post was edited on 03-02-2008 at 06:14 PM by Jesus.
Man is least himself when he is in his own person. Give him a mask and he will tell you the truth. (Oscar Wilde)
03-02-2008 06:11 PM
Profile PM Find Quote Report
Spunky
Former Super Mod
*****

Avatar

Posts: 3658
Reputation: 61
36 / Male / Flag
Joined: Aug 2006
RE: First script testing
Fair enough, I never checked for a [0] :p



I've created a plsc file with an improved version of the script. It uses a global array rather than defining it each time you receive a message.

The random number now generates between 0 and the number of array entries meaning if you added more you would not have to update the random number code.

Some lines could be put into one so I did that to make it a bit more compact.

It uses CookieRevised's RegExp for getting commands and parameters from messages.

I've put in a try...catch statement in case something does go wrong, we want to alert the user, but not send the message.

I also added the command /ponder to the command helper window so it will show up their too.




Take a look at the changes and if you need help understanding anything... I'll be here lol

.plsc File Attachment: TTP.plsc (3.54 KB)
This file has been downloaded 108 time(s).
<Eljay> "Problems encountered: shit blew up" :zippy:
03-12-2008 04:49 PM
Profile PM Find Quote Report
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
Joined: Dec 2002
Status: Away
RE: First script testing
The array contents should be in a text file however here is a nice way of doing it as well.

code:
// This was made by Paul Dean - Version 1.0
// Improved by SpunkyLoveMuff - Version 1.1
// Improved by matty - Version 1.2

var rn_txt = new Array("Why isn't phonetic spelled the way it sounds?",
                       "Why are there interstate highways in Hawaii?",
                       "Why are there flotation devices under plane seats instead of parachutes?",
                       "Why are cigarettes sold in petrol stations when smoking is prohibited there?",
                       "Why do fat chance and slim chance mean the same thing?",
                       "If you can't drink and drive, why do you need a driver's license to buy liquor, and why do bars have parking spaces?",
                       "Do you need a silencer if you are going to shoot a mime?",
                       "Have you ever imagined a world with no hypothetical situations?",
                       "How does the guy who drives the snowplow get to work in the mornings?",
                       "If 7-11 is open 24 hours a day, 365 days a year, why are there locks on the doors?",
                       "If a cow laughed real hard, would milk come out her nose?",
                       "If nothing ever sticks to Teflon, how do they make Teflon stick to the pan?",
                       "If you tied buttered toast to the back of a cat and dropped it from a height, what would happen?",
                       "If you're in a vehicle going the speed of light, what happens when you turn on the headlights?",
                       "Why do they put Braille dots on the keypad of the drive-up ATM?",
                       "Why do we drive on parkways and park on driveways?",
                       "Why isn't palindrome spelled the same way backwards as it is forwards?",
                       "Why is it that when you transport something by car, it's called a shipment, but when you transport something by ship, it's called cargo?",
                       "If a black box in a plane is indestructible, why can't they make the whole plane out of it?",
                       "Why is it that when you're driving and looking for an address, you turn down the volume on the radio?",
                       "If someone invented instant water, what would they mix it with?",
                       "Why is it called a TV set when you only get one?",
                       "Why does your nose run and your feet smell?",
                       "Why does an alarm clock go off when it begins ringing?",
                       "Why does cleave mean both split apart and stick together?",
                       "Why is it, whether you sit up or sit down, the result is the same?",
                       "Why is there an expiry date on my sour cream container?",
                       "Why call it a building if it's already been built?",
                       "Why do kamikaze pilots wear helmets?",
                       "Is it true that cannibals don't eat clowns because they taste funny?",
                       "Does 'virgin wool' come from sheep the shepherd hasn't caught yet?",
                       "What do sheep count when they can't get to sleep?",
                       "When you choke a Smurf, what color does it turn?",
                       "Do blind Eskimos heave seeing-eye sled dogs?",
                       "Do they have reserved parking for non-handicap people at the Special Olympics?",
                       "How come wrong numbers are never busy?",
                       "Do radioactive cats have 18 half-lives?",
                       "Why call it take a dump, when you leave something behind?",
                       "What was the best thing before sliced bread?",
                       "Why do we call it a hot water heater if the water is already hot?",
                       "If you throw a cat out a car window does it become kitty litter?",
                       "If corn oil comes from corn, where does baby oil come from?",
                       "If it's tourist season, why can't we shoot them?",
                       "After eating, do amphibians have to wait one hour before getting out of the water?",
                       "How can there be self-help groups?",
                       "If a mute swears, does his mother make him wash his hands with soap?",
                       "If someone with multiple personalities threatens to kill himself, is it considered a hostage situation?",
                       "Instead of talking to your plants, if you yelled at them would they still grow, but only to be troubled and insecure?",
                       "Isn't it a bit unnerving that doctors call what they do practice?",
                       "It is hard to understand how a cemetery raised its burial cost and blamed it on the cost of living.",
                       "If Barbie is so popular, why do you have to buy her friends?",
                       "Why did God give men nipples?",
                       "Why do you wear a pair of panties and only one bra?",
                       "If you spin an Oriental person around and around, does he become disorientated?",
                       "If a vegetable goes into a coma, is it called a person?",
                       "If you wear an antennae to a wedding, would the reception be better?",
                       "If you put a chameleon in a mirrored box what color would it change to?",
                       "Why is there an 's' in lisp?",
                       "If the cops arrest a mime, do they tell him he has the right to remain silent?",
                       "If one synchronized swimmer drowns, do the rest end up drowning as well?",
                       "If a man is standing in the middle of the forest speaking and there is no woman around to hear him, is he still wrong?");

function OnEvent_ChatWndSendMessage(ChatWnd, Message){
    if (/^\/([^\s\/]+)\s*([\s\S]*)$/.exec(Message) !== null) {
        switch (RegExp.$1.toLowerCase()) {
        case 'ponder':
            try{
                return rn_txt[Math.round((rn_txt.length-1)*Math.random())];   
            }catch(e){
                MsgPlus.DisplayToast("Error!", "Something bad happened! :o");
                Debug.Trace(e.message);
                return "";
            }
        }
    }
}

function OnGetScriptCommands(){
    return '<ScriptCommands><Command><Name>ponder</Name><Description>What will you think of today?</Description></Command></ScriptCommands>';
}

Why is there a need to store the Script Commands in a variable then return it? Why not just return the string?

This post was edited on 03-12-2008 at 05:07 PM by matty.
03-12-2008 05:06 PM
Profile E-Mail PM Find Quote Report
Spunky
Former Super Mod
*****

Avatar

Posts: 3658
Reputation: 61
36 / Male / Flag
Joined: Aug 2006
RE: First script testing
I figured a separate txt file would be larger overall because of the function to read it and split it into lines.

The commands were like that because I just copied and pasted the code from another one of my own scripts and edited it to suite :p
<Eljay> "Problems encountered: shit blew up" :zippy:
03-12-2008 05:44 PM
Profile PM Find Quote Report
markee
Veteran Member
*****

Avatar

Posts: 1622
Reputation: 50
36 / Male / Flag
Joined: Jan 2006
RE: First script testing
Matty needs to learn how to do better randomness....

code:
return rn_txt[Math.round((rn_txt.length-1)*Math.random())];

Should be:

code:
return rn_txt[Math.floor((rn_txt.length)*Math.random())];

Otherwise the first and last variable only have half the probability of being chosen as any other (assuming Math.random is truely random).
[Image: markee.png]
03-13-2008 01:11 PM
Profile PM Find Quote Report
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
Joined: Dec 2002
Status: Away
RE: First script testing
quote:
Originally posted by markee
Matty needs to learn how to do better randomness....

code:
return rn_txt[Math.round((rn_txt.length-1)*Math.random())];

Should be:

code:
return rn_txt[Math.floor((rn_txt.length)*Math.random())];

Otherwise the first and last variable only have half the probability of being chosen as any other (assuming Math.random is truely random).
Clearly I didn't alter that function except for removing the undeclared variable.
03-13-2008 01:41 PM
Profile E-Mail PM Find Quote Report
Volv
Skinning Contest Winner
*****

Avatar

Posts: 1233
Reputation: 31
35 / Male / Flag
Joined: Oct 2004
RE: First script testing
quote:
If you tied buttered toast to the back of a cat and dropped it from a height, what would happen?
Haha!
03-13-2008 02:30 PM
Profile PM Find Quote Report
Jesus
Scripting Contest Winner
****

Avatar
Koffie, my cat ;)

Posts: 623
Reputation: 15
38 / Male / Flag
Joined: Jul 2005
RE: First script testing
quote:
If you tied buttered toast to the back of a cat and dropped it from a height, what would happen?
depends on whether you tie it on butter side up or down :P
Man is least himself when he is in his own person. Give him a mask and he will tell you the truth. (Oscar Wilde)
03-13-2008 04:03 PM
Profile PM Find Quote Report
« 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