Need help!

Anything VBScript-related, including Windows Script Host, WMI, ADSI, and more.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
User avatar
tech_soul8
Posts: 26
Joined: Mon Apr 02, 2012 8:46 pm

Need help!

Post by tech_soul8 »

I'm stuck on one example code from a book which I'm reading and I need some help.

Here is the .zip file containing a script

Script.zip

It's about tic tac toe game. What I don't understand is how script knows after the player makes his selection where to place "X" or "O" into the right section. There are only variables representing each section but how that sections are identified? I mean there is no some kind of coordinates or something like that...

If someone can paste me a piece of code from a script that does that part of work and explain it to me I would be grateful. (I hope it will be you jvierra)

Thanks in advance!

User avatar
tech_soul8
Posts: 26
Joined: Mon Apr 02, 2012 8:46 pm

Need help!

Post by tech_soul8 »

I'm stuck on one example code from a book which I'm reading and I need some help.

Here is the .zip file containing a script

Script.zip

It's about tic tac toe game. What I don't understand is how script knows after the player makes his selection where to place "X" or "O" into the right section. There are only variables representing each section but how that sections are identified? I mean there is no some kind of coordinates or something like that...

If someone can paste me a piece of code from a script that does that part of work and explain it to me I would be grateful. (I hope it will be you jvierra)

Thanks in advance!

User avatar
tech_soul8
Posts: 26
Joined: Mon Apr 02, 2012 8:46 pm

Need help!

Post by tech_soul8 »

Function MarkPlayerSelection()
If strPlayerInput = "A1" Then
A1 = strPlayer
End If
If strPlayerInput = "A2" Then
A2 = strPlayer
End If
If strPlayerInput = "A3" Then
A3 = strPlayer
End If
If strPlayerInput = "B1" Then
B1 = strPlayer
End If
If strPlayerInput = "B2" Then
B2 = strPlayer
End If
If strPlayerInput = "B3" Then
B3 = strPlayer
End If
If strPlayerInput = "C1" Then
C1 = strPlayer
End If
If strPlayerInput = "C2" Then
C2 = strPlayer
End If
If strPlayerInput = "C3" Then
C3 = strPlayer
End If
End Function

I know it's this part of code but when player makes his selection how "X" or "O" are placed exactly in the middle of a cell and how script identifies each row and column and knows where to place each sign?



tech_soul82012-05-15 13:56:03

User avatar
tech_soul8
Posts: 26
Joined: Mon Apr 02, 2012 8:46 pm

Need help!

Post by tech_soul8 »

Oh...!!!! I overlooked it!

It's this part of code that does the job:

Function DisplayBoard() 'Display the game board
strPlayerInput = UCase(InputBox(vbCrLf & _
strNotificationMsg & _
vbCrLf & vbCrLf & vbCrLf & vbCrLf & _
vbTab & "1" & vbTab & vbTab & "2" & vbTab & vbTab & "3" & vbCrLf & _
vbCrLf & vbTab & vbTab & "|" & vbTab & vbTab & "|" & vbTab & _
vbCrLf & "A" & vbTab & A1 & vbTab...

the variables are embedded into the DisplayBoard function.

Now that mystery is gone I can continue to move on... :)tech_soul82012-05-15 15:35:06

jvierra
Posts: 14543
Joined: Tue May 22, 2007 9:57 am
Contact:

Need help!

Post by jvierra »

Follow the code a line at a time. YOu willsee how it is structured to gather input and disply a result. After each prompt teh variables are set and teh screen is redrawn. There is no magic. It is just simple linear code.

This is a good instructional game. Pretend you are the computer. Take a piece of paper and execute each write to the paper as it occurs. List the variables as they are declared and change their values as the lines of code change them. When you have completed one full inpui by each player you will know how the game works and how a compluter program works.

It would also help for you to print the code on paper so it is easier to follow. Put one function on each piece of paper so functions are easy to "call".

As you execute teh game on papaer draw a flow chart showing how each funtion is called and where it calls and what it returns or changes.
jvierra2012-05-15 15:38:57

jvierra
Posts: 14543
Joined: Tue May 22, 2007 9:57 am
Contact:

Need help!

Post by jvierra »

Good Solution.
LIke I posted; it is a good learning tool. There was nothing I saw that was tricky. It is all pretty straight-up.

Locked