# Did Not Understand Diagnol Check Code in Tic Tac Toe Example

#### SachGw

##### Member
Hi Guys,I am having a bit of problem understanding the Logic in following piece of code from Tic Tac Toe example.Could anybody please explain me how the code works.. :sign0085:

B4X:
'Check diagonals
found = True
For i = 0 To 2
found = found AND Buttons(i, i).Text = Player
Next
If found = True Then Return True

found = True
For i = 0 To 2
found = found AND Buttons(i, 2 - i).Text = Player
Next
If found = True Then Return True
Return False

#### Widget

##### Well-Known Member
There are 2 diagonals to check so there are two loops.

The first loop checks for (0,0), (1,1), (2,2)
The second loop checks for (0,2),(1,1),(2,0)

Widget

#### SachGw

##### Member
Oh, now I understood it..thank you..

#### Hero post

##### Member
What Button has been touched

I want to use part of the tictactoe code for4 an app of mine, but I need to know what button has been clicked.
I have three rows of buttons, but I am unclear on how to i:sign0104:dentify the button.

#### Erel

##### B4X founder
Staff member
You should use the Sender keyword to get the button that raised the event.

Replies
4
Views
2K
Replies
4
Views
567
Replies
1
Views
749
Replies
1
Views
891
Share My Creation Tic Tac Toe Multiplayer
Replies
1
Views
3K