krystian334

unread,
May 4, 2019, 3:33:47 AM5/4/19
to MIT App Inventor Forum

Hello guys ! Im trying to make a TicToe game for me and my friends, i have a issue: When dealing with squares in a specific way (see Ordine.png) the application does not realize that X or O wins, some help? Sorry for bad english.
blocks (1).png
Ordine.png
TestsVasile.aia

Italo

unread,
May 4, 2019, 8:25:26 AM5/4/19
to MIT App Inventor Forum
Your comparisons doesn't make sense with the button numbers you put in your image. Are those correct? Why didn't you number the buttons in order from top left down to bottom right to make things easier?

Another thing I notice is that your app is not checking if the button is empty when one of the players touch it. You should do that. If there's already an X and I go and touch it again in the next turn, it will change to an O.

krystian334

unread,
May 4, 2019, 8:52:44 AM5/4/19
to MIT App Inventor Forum
yes, I know the other player can change the letter of the box, but I chose not to fix this problem in order not to load the image too much, the numbers in the image show the order they use when the bug

Italo

unread,
May 4, 2019, 8:55:19 AM5/4/19
to MIT App Inventor Forum
And the problem you are asking about is because you are asking if three buttons have the same text, then check who wins. And that is happening with three empty buttons before it gets to ask for your winning combination. Three empty buttons are in fact a "winning" in your logic.
So you need to check that the text in the buttons you are comparing are not empty strings.

krystian334

unread,
May 4, 2019, 10:13:04 AM5/4/19
to MIT App Inventor Forum
As you can see in the picture, my app is checking if one button from combination is X or O else, nothing is happening

Italo

unread,
May 4, 2019, 10:42:28 AM5/4/19
to MIT App Inventor Forum
Yes, you do that, but after you ask if three buttons are the same! So it will enter in that as true and then when you ask if it's an X or an O it will do nothing, that's why your app never shows who wins.
When one IF returns true, the other ELSE IF are skipped.

EXAMPLE: You are checking if button1 = button2 AND if button1 = button3.
That will return true when any of this combinations is found
"X" "X" "X"
"O", "O", "O"
"<empty> ", "<empty> ", "<empty>"

So, like I said before, check that the initial button.text is not an empty string.

krystian334

unread,
May 5, 2019, 3:43:55 AM5/5/19
to MIT App Inventor Forum
Yes, thank you so much ! This are my blocks now: 
blocks (2).png

Ghica

unread,
May 5, 2019, 9:02:20 AM5/5/19
to MIT App Inventor Forum
And, in your Win procedure as it is now, you should check that the button pressed had blank text in it, otherwise you can write an O over an X or the other way around.
It would also be helpful to have a reset button, which resets all button values and allows you too restart the game.
Cheers, Ghica.

p.s. What version of App Inventor are you using? Mine complains that you are using a "newer version".

Reply all
Reply to author
Forward
0 new messages