Shoutbox

[release] Tic Tac Toe 2 - 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: [release] Tic Tac Toe 2 (/showthread.php?tid=69430)

[release] Tic Tac Toe 2 by roflmao456 on 12-12-2006 at 11:18 PM

Tic Tac Toe 2


Play with your contact a game of Tic Tac Toe!

here it is.................

Command: type

/tic

/tac

or

/toe

to start a game

works if they have the script too..
RE: [release] Tic Tac Toe 2 by DarkMe on 12-12-2006 at 11:40 PM

* DarkMe downloads
Good Script (y)

no i dont have to wait til wlm starts the app :p


RE: [release] Tic Tac Toe 2 by Spunky on 12-12-2006 at 11:57 PM

Nice to see me in the about box ^o)

I thought I replaced that ugly white box with a transparent one to blend in?

As for opening a "Chat Window"... what do you think people talk in anyway? It doesn't NEED one.

Hope you fixed the logic errors in this one after you so kindly wrecked mine :refuck:

EDIT:

code:
var SW_MINIMIZE = 0x6;
Interop.Call('user32', 'ShowWindow', game.Handle, SW_MINIMIZE);


Why not:
code:
Interop.Call('user32', 'ShowWindow', game.Handle, 0x6);


RE: RE: [release] Tic Tac Toe 2 by deAd on 12-13-2006 at 12:44 AM

quote:
Originally posted by SpunkyLoveMuff
code:
var SW_MINIMIZE = 0x6;
Interop.Call('user32', 'ShowWindow', game.Handle, SW_MINIMIZE);


Why not:
code:
Interop.Call('user32', 'ShowWindow', game.Handle, 0x6);


in my opinion its better/more convenient to use constants like that, however I'd declare them globally instead of locally in the function :/
RE: [release] Tic Tac Toe 2 by CookieRevised on 12-13-2006 at 01:52 AM

quote:
Originally posted by deAd
quote:
Originally posted by SpunkyLoveMuff
code:
var SW_MINIMIZE = 0x6;
Interop.Call('user32', 'ShowWindow', game.Handle, SW_MINIMIZE);


Why not:
code:
Interop.Call('user32', 'ShowWindow', game.Handle, 0x6);


in my opinion its better/more convenient to use constants like that, however I'd declare them globally instead of locally in the function :/

If it is just for 1 line of code, like in this script, you can do something like:

Interop.Call('user32', 'ShowWindow', game.Handle, /* SW_MINIMIZE */ 0x6);

-------------------------------------------------------------

anyways, roflmao456

some tips:

- Start by indenting lines of code properly with tabs. This will make possible errors and optimizations visible in an instant.

- Remove the need for all those global variables. You will need some global variables, but not all of those.

- Declaring an activex object in global space isn't needed at all. Declare it where you need it.

- Use an array as your play grid instead of all those sequencial variables a1, a2, a3, b1, b2, etc...

- Determining who won can be made shorter. And it also contains a duplicated check for both sides btw.

Don't check each side individually, but simply check if squares are equal (using the method above). And if they are, only then determine to which side the squares are belonging. In other words, use the opposite of the logic you use now. This will make the whole checking faster and shorter and will reduce the needed checks from the currently 18 to 8 checks.

And if you take in account the last move (which is the only one which might trigger a win situation of course) and you use an array as your playing grid you could reduce this even further to only 3 or 4 checks (for a horizontal, a vertical and a diagonal solution).

So you don't need all those checks since the only way that someone can have 3 in a row is when the middle square of the sequence is equal to the left and right side square of it, or upper and lower side of it, or up-left and down-right, or down-left and up-right. And if so, any of the three squares making a solution will always hold the sign of the winning party. Or even shorter: if a winning solution is made, the winning party will always be the one who last made a move, thus you actually don't even need to check the signs in the squares.

- Some code in checkWin() is also duplicated, so remove that and put it above the structure where it is nested in (the alertmsg and canMove variables).

In addition to this, since the only thing you change in the         if(won == "O"){} check is the name of the side that won, you can easly remove that check and simply place won as a variable in that sentence since it already identifies who won.

- In the OnEvent_Timer(timerId) function replaces those if_then_else's with a switch statement.

- Change the "!tic-tac-toe" command to "/tic-tac-toe". Commands in Plus! start with "/", so that is what the user is used to.
(and personally I would remove the "-" in the command, but that's just pure personal preference)

- Take in account that the user can type commands in uppercase to. So add a .tolowercase() to the command catching routines.

- The rest is just a big mess in code atm and I cba to fix all the indenting first to check the code further, see point 1 ;)

- Change things like:
code:
if (Origin != Messenger.MyName) {
    if (Message.substr(0,12) == "!tic-tac-toe"){
    }
}
if (Origin == Messenger.MyName){
    if (Message.substr(0,12) == "!tic-tac-toe"){
    }
}
to:
code:
if (Message.substr(0,12) === "!tic-tac-toe"){
    if (Origin === Messenger.MyName) {
    } else {
    }
}
which is shorter and easier to maintain.

- Chage stuff like
code:
if(Message.substr(0,3)!="!a1"){
if(Message.substr(0,3)!="!a2"){
if(Message.substr(0,3)!="!a3"){
if(Message.substr(0,3)!="!a1"){
if(Message.substr(0,3)!="!a2"){
if(Message.substr(0,3)!="!a3"){
if(Message.substr(0,3)!="!b1"){
if(Message.substr(0,3)!="!b2"){
if(Message.substr(0,3)!="!b3"){
if(Message.substr(0,3)!="!c1"){
if(Message.substr(0,3)!="!c2"){
if(Message.substr(0,3)!="!c3"){
//dosomething
}}}}}}}}}
to at least 1 check using an AND operator.
Or better yet, use a single regular expression.

Also you use such a bunch of checks twice inside an if_then_else, once for the true part and once for the false part. So switch this logic around and use those bunch of checks as the first main checks and only then do the check you otherwise did first (if(chat.GetControlText("chatAll")){).


- the design of the game window is nice (y)
RE: [release] Tic Tac Toe 2 by Spunky on 12-13-2006 at 02:07 AM

quote:
Originally posted by CookieRevised
Take in account that the user can type commands in uppercase to. So add a .tolowercase() to the command catching routines

I think thats just a command that gets sent by the script to initiate the other players window so it will always be the same case.

Some problems with this script are partially my fault as the code its loosly based on a script I attempted when I first started scripting. However, functions such as canMove were added by ROFLMAO and are nothing to do with me.

@ROFLMAO: I know I said just release it under your name, but I didn't mean I wouldn't like any credit for the things that I did do

EDIT:
quote:
Originally posted by CookieRevised
If it is just for 1 line of code, like in this script, you can do something like:

Interop.Call('user32', 'ShowWindow', game.Handle, /* SW_MINIMIZE */ 0x6);

Just to make it clear that was the point I was making, about it not needing a constant for a single use
RE: [release] Tic Tac Toe 2 by CookieRevised on 12-13-2006 at 02:11 AM

quote:
Originally posted by SpunkyLoveMuff
I think thats just a command that gets sent by the script to initiate the other players window so it will always be the same case.
indeed, !tictactoe might not have been the best example, but my comment about taking in account letter case still stands.

RE: RE: [release] Tic Tac Toe 2 by deAd on 12-13-2006 at 02:58 AM

quote:
Originally posted by SpunkyLoveMuff
quote:
Originally posted by CookieRevised
If it is just for 1 line of code, like in this script, you can do something like:

Interop.Call('user32', 'ShowWindow', game.Handle, /* SW_MINIMIZE */ 0x6);

Just to make it clear that was the point I was making, about it not needing a constant for a single use

Oh, right. I'm used to having tons and tons of constants in my code, so what I said makes more sense to me :P
RE: [release] Tic Tac Toe 2 by Spunky on 12-13-2006 at 04:01 AM

quote:
Originally posted by CookieRevised
the design of the game window is nice

* Spunky does a little dance (and looks a mess doing it)

I wanted to be different so I started working on the interfaces a bit more to try and make something... different

@ROFLMAO: You should probably also display a warning somewhere that clsoing the conversation window will end the current game (as it will destroy the ChatWnd that you send the messages to
RE: [release] Tic Tac Toe 2 by roflmao456 on 12-13-2006 at 11:44 PM

quote:
Originally posted by CookieRevised

code:
if(Message.substr(0,3)!="!a1"){
if(Message.substr(0,3)!="!a2"){
if(Message.substr(0,3)!="!a3"){
if(Message.substr(0,3)!="!a1"){
if(Message.substr(0,3)!="!a2"){
if(Message.substr(0,3)!="!a3"){
if(Message.substr(0,3)!="!b1"){
if(Message.substr(0,3)!="!b2"){
if(Message.substr(0,3)!="!b3"){
if(Message.substr(0,3)!="!c1"){
if(Message.substr(0,3)!="!c2"){
if(Message.substr(0,3)!="!c3"){
//dosomething
}}}}}}}}}


that is saying "if the message at 0,3 doesn't equal *this*, do this." ... should it be "if the message at 0,3 equals *this*, do this" ?

quote:
Originally posted by CookieRevised

- the design of the game window is nice (Y)


dont say that 2 me :O say that to SpunkyLM
RE: [release] Tic Tac Toe 2 by NanaFreak on 12-13-2006 at 11:53 PM

bug?

[Image: tttbug.png]

also nice game...

(Y) good job on the windows too spunky


RE: RE: [release] Tic Tac Toe 2 by roflmao456 on 12-13-2006 at 11:55 PM

quote:
Originally posted by NanaFreak
bug?

[Image: tttbug.png]

also nice game...

(Y) good job on the windows too spunky


that was.. the old version
RE: [release] Tic Tac Toe 2 by NanaFreak on 12-14-2006 at 12:02 AM

woops sorry i forgot to remove the old script :S

(Y) works fine

edit: one thing would be to make the quick chat window better by making the text add to the bottom not at the top


RE: RE: [release] Tic Tac Toe 2 by CookieRevised on 12-19-2006 at 02:41 AM

quote:
Originally posted by roflmao456
quote:
Originally posted by CookieRevised

code:
if(Message.substr(0,3)!="!a1"){
if(Message.substr(0,3)!="!a2"){
if(Message.substr(0,3)!="!a3"){
if(Message.substr(0,3)!="!a1"){
if(Message.substr(0,3)!="!a2"){
if(Message.substr(0,3)!="!a3"){
if(Message.substr(0,3)!="!b1"){
if(Message.substr(0,3)!="!b2"){
if(Message.substr(0,3)!="!b3"){
if(Message.substr(0,3)!="!c1"){
if(Message.substr(0,3)!="!c2"){
if(Message.substr(0,3)!="!c3"){
//dosomething
}}}}}}}}}


that is saying "if the message at 0,3 doesn't equal *this*, do this." ... should it be "if the message at 0,3 equals *this*, do this" ?
No

it should be if the message at 0,3 doesn't equal *this* AND doesn't equal *this* AND doesn't equal *this  AND doesn't equal *this  AND doesn't equal *this  AND doesn't equal *this  AND doesn't equal *this  AND doesn't equal *this  AND doesn't equal *this  AND doesn't equal *this*, then do something.

quote:
Originally posted by CookieRevised
- Chage stuff like
code:
if(Message.substr(0,3)!="!a1"){
if(Message.substr(0,3)!="!a2"){
if(Message.substr(0,3)!="!a3"){
if(Message.substr(0,3)!="!a1"){
if(Message.substr(0,3)!="!a2"){
if(Message.substr(0,3)!="!a3"){
if(Message.substr(0,3)!="!b1"){
if(Message.substr(0,3)!="!b2"){
if(Message.substr(0,3)!="!b3"){
if(Message.substr(0,3)!="!c1"){
if(Message.substr(0,3)!="!c2"){
if(Message.substr(0,3)!="!c3"){
//dosomething
}}}}}}}}}
to at least 1 check using an AND operator.
Or better yet, use a single regular expression.

So start by properly indenting your entire code (isn't the first time I strongly suggest you do this) and see what you exactly made with all those IF THEN's. A massive bunch of nested IF THEN....

This entire forest of IF THENs can be made into 1 simple check using alogical AND operator (aka: use  &&).


...or learn regular expressions and put that entire bunch into one short check. PS: nope I'm not going to give you the regular expression as I want you to convert that whole bunch into 1 proper IF THEN check first :p