Shoutbox

First script testing - 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: First script testing (/showthread.php?tid=82066)

First script testing by snazzpompey on 03-02-2008 at 05:46 PM

thought creating a list of random things to ponder would be a laugh try it out with the attatchments works 100%


RE: First script testing by Spunky on 03-02-2008 at 05:52 PM

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


RE: First script testing by Jesus on 03-02-2008 at 06:11 PM

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.
RE: First script testing by Spunky on 03-12-2008 at 04:49 PM

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
RE: First script testing by matty on 03-12-2008 at 05:06 PM

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?
RE: First script testing by Spunky on 03-12-2008 at 05:44 PM

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


RE: First script testing by markee on 03-13-2008 at 01:11 PM

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).
RE: First script testing by matty on 03-13-2008 at 01:41 PM

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.
RE: First script testing by Volv on 03-13-2008 at 02:30 PM

quote:
If you tied buttered toast to the back of a cat and dropped it from a height, what would happen?
Haha!

RE: First script testing by Jesus on 03-13-2008 at 04:03 PM

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