Making compartment inactive in Tic-Tac-Toe game

Hello All

I’ve been stuck on this part of a tic-tac-toe game for a while now.

I am trying to have it where after a compartment is filled w/ “X” or an “O” that compartment becomes inactive and if clicked on again the touch id stays the same.

Any help will be appreciated.

Thanks.

d = display w10 = d.contentWidth \* .1 h10 = d.contentHeight \* .1 w20 = d.contentWidth \* .2 h20 = d.contentHeight \* .2&nbsp; w40 = d.contentWidth \* .4 h40 = d.contentHeight \* .4 w60 = d.contentWidth \* .6 h60 = d.contentHeight \* .6 w80 = d.contentWidth \* .8 h80 = d.contentHeight \* .8 ----DRAW LINES FOR BOARD local lline = d.newLine(w40,h20,w40,h80 ) lline.strokeWidth = 5 local rline = d.newLine(w60,h20,w60,h80 ) rline.strokeWidth = 5 local bline = d.newLine(w20,h40,w80,h40 ) bline.strokeWidth = 5 local tline = d.newLine(w20,h60,w80,h60 ) tline.strokeWidth = 5 --PLACE BOARD COMPARTMENT DIMENSIONS IN TABLE board ={ &nbsp;&nbsp; &nbsp; &nbsp; {"tl", 1, w20, h40, w40, h20,0,0, true}, &nbsp; &nbsp; {"tm",2, w40,h40,w60,h20,0,0, true}, &nbsp; &nbsp; {"tr",3, w60,h40,w80,h20,0,0, true}, &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; {"ml", 4, w20, h60, w40, h40,0,0, true}, &nbsp; &nbsp; {"mm",5, w40,h60,w60,h40,0,0, true}, &nbsp; &nbsp; {"mr",6, w60,h60,w80,h40,0,0, true}, &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; {"bl", 7, w20, h80, w40, h60,0,0, true}, &nbsp; &nbsp; {"bm",8, w40,h80,w60,h60,0,0, true}, &nbsp; &nbsp; {"br",9, w60,h80,w80,h60,0,0, true} &nbsp; } -- local idx = 0 --FILL COMPARTMENT W/ COLOR & "X"/"O" WHEN TOUCHED local function fill (event) &nbsp; if event.phase == "began" then &nbsp;&nbsp; --MANAGE TOUCH ID &nbsp; &nbsp; if event.x \> w20 and event.x \< w80 then &nbsp; &nbsp; &nbsp; if event.y \> h20 and event.y \< h80 then &nbsp; &nbsp; &nbsp; &nbsp; idx = idx + 1 &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; event.id = idx&nbsp; if event.id \>= 2 then &nbsp; &nbsp; &nbsp; idx = 0 &nbsp; &nbsp; &nbsp;end&nbsp; &nbsp; end &nbsp; end --------------------------------------- &nbsp; --MANAGE TURNS &nbsp; &nbsp; for t = 1, 9 do &nbsp; &nbsp; &nbsp; if event.x \> board[t][3] and event.x \< board [t][5] then &nbsp; &nbsp; &nbsp; &nbsp; if event.y \< board[t][4] and event.y \> board[t][6] then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if event.id == 1 and board[t][8] == 0 then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;board[t][7] = 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;board[t][8] = 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;elseif event.id == 2 and board[t][8] == 0 then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;board[t][7] = 2 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;board[t][8] = 1&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end &nbsp; &nbsp; &nbsp; &nbsp; end &nbsp; &nbsp; &nbsp; end&nbsp; &nbsp; &nbsp; end &nbsp; &nbsp; end ------------------------------------------ --FILL COMPARTMENT WITH X/O &nbsp; for i = 1, 9 do&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; if board[i][7] == 1 then &nbsp; &nbsp; &nbsp; &nbsp;r = d.newRect(board[i][3],board [i][6],w20,h20) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; r:setFillColor(1,1,0) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; r.anchorX=0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; r.anchorY=0 &nbsp; &nbsp; &nbsp; t = d.newText("X",board[i][3] + w10, board [i][6] + h10, native.systemFontBold,64) &nbsp; &nbsp; elseif board[i][7] == 2 then &nbsp; &nbsp; &nbsp; &nbsp;r = d.newRect(board[i][3],board [i][6],w20,h20) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; r:setFillColor(1,0,0) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; r.anchorX=0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; r.anchorY=0 &nbsp; &nbsp; &nbsp; t = d.newText("O",board[i][3] + w10, board [i][6] + h10, native.systemFontBold,64) &nbsp; &nbsp; end&nbsp; &nbsp; end end Runtime:addEventListener("touch", fill)

If I’m getting it right, you can use button:setEnabled() function when clicked.

https://docs.coronalabs.com/api/type/ButtonWidget/setEnabled.html

hey bgmadclown

I am not currently using buttons in the code so am not sure  button:setEnabled() function will work as it stands now.

But you did give me the idea to change the compartment fills to buttons instead of regular rectangles.

I will try this.

Thank You!

Funny thing, looking at the code again, I can’t recall why I said button:setEnabled() since you are not using any buttons. I’m sorry about that.

If you are going to stick to your current solution, you can add an attribute like isActive to the image / rect you are clicking, add a simple if clause to control isActive and when you click it the first time, you can set it to false.

local function handleTouch (event) if (event.phase == "ended") then if (event.target.isActive)then event.target.isActive = false -- change rect to X or O else -- give error end end return true end rect.isActive = true rect:addEventListener("touch", handleTouch)

I added the buttons to the game and it worked out very well.

I will play around with the other code you supplied.

Thanks for your help!!

d = display w10 = d.contentWidth \* .1 h10 = d.contentHeight \* .1 w20 = d.contentWidth \* .2 h20 = d.contentHeight \* .2&nbsp; w40 = d.contentWidth \* .4 h40 = d.contentHeight \* .4 w60 = d.contentWidth \* .6 h60 = d.contentHeight \* .6 w80 = d.contentWidth \* .8 h80 = d.contentHeight \* .8 local widget = require( "widget" ) ----DRAW LINES FOR BOARD local lline = d.newLine(w40,h20,w40,h80 ) lline.strokeWidth = 5 local rline = d.newLine(w60,h20,w60,h80 ) rline.strokeWidth = 5 local bline = d.newLine(w20,h40,w80,h40 ) bline.strokeWidth = 5 local tline = d.newLine(w20,h60,w80,h60 ) tline.strokeWidth = 5 --PLACE BOARD COMPARTMENT DIMENSIONS IN TABLE board ={ &nbsp;&nbsp; &nbsp; &nbsp; {"tl", 1, w20, h40, w40, h20,0,0, true}, &nbsp; &nbsp; {"tm",2, w40,h40,w60,h20,0,0, true}, &nbsp; &nbsp; {"tr",3, w60,h40,w80,h20,0,0, true}, &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; {"ml", 4, w20, h60, w40, h40,0,0, true}, &nbsp; &nbsp; {"mm",5, w40,h60,w60,h40,0,0, true}, &nbsp; &nbsp; {"mr",6, w60,h60,w80,h40,0,0, true}, &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; {"bl", 7, w20, h80, w40, h60,0,0, true}, &nbsp; &nbsp; {"bm",8, w40,h80,w60,h60,0,0, true}, &nbsp; &nbsp; {"br",9, w60,h80,w80,h60,0,0, true} &nbsp; } -- --Notifications --Notify player if match is found or not local win = display.newText("", 0, 0, native.systemFont, 26) win.anchorX = 0 win.anchorY = 0 win:setTextColor(1, 1, 1) win.x = display.contentWidth \* .65 -- Function to handle button events local function handleButtonEvent( event ) &nbsp; &nbsp; if ( "ended" == event.phase ) then &nbsp; &nbsp; &nbsp; &nbsp;button1:setEnabled(false) &nbsp; &nbsp; end end local idx = 0 gameover = false --FILL COMPARTMENT W/ COLOR & "X"/"O" WHEN TOUCHED local function fill (event) &nbsp; if event.phase == "began" then &nbsp;&nbsp; &nbsp; --MANAGE TOUCH ID &nbsp; &nbsp; if event.x \> w20 and event.x \< w80 then &nbsp; &nbsp; &nbsp; if event.y \> h20 and event.y \< h80 then &nbsp; &nbsp; &nbsp; &nbsp; idx = idx + 1 &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; event.id = idx&nbsp; &nbsp; &nbsp; &nbsp; if event.id \>= 2 then &nbsp; &nbsp; &nbsp; idx = 0 &nbsp; &nbsp; &nbsp; end&nbsp; &nbsp; &nbsp; end &nbsp; end --------------------------------------- &nbsp; &nbsp;--MANAGE TURNS &nbsp; &nbsp; for t = 1, 9 do &nbsp; &nbsp; &nbsp; if event.x \> board[t][3] and event.x \< board [t][5] then &nbsp; &nbsp; &nbsp; &nbsp; if event.y \< board[t][4] and event.y \> board[t][6] then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if event.id == 1 and board[t][8] == 0 then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;board[t][7] = 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;board[t][8] = 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;elseif event.id == 2 and board[t][8] == 0 then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;board[t][7] = 2 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;board[t][8] = 1&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end &nbsp; &nbsp; &nbsp; &nbsp; end &nbsp; &nbsp; &nbsp; end&nbsp; &nbsp; &nbsp; end &nbsp; &nbsp; end &nbsp; ------------------------------------------ &nbsp; &nbsp;--FILL COMPARTMENT WITH X/O &nbsp; for i = 1, 9 do&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; if board[i][7] == 1 then &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; -- Create the widget button1 = widget.newButton( &nbsp; &nbsp; { &nbsp; &nbsp; &nbsp; &nbsp; label = "", &nbsp; &nbsp; &nbsp; &nbsp; onEvent = handleButtonEvent, &nbsp; &nbsp; &nbsp; &nbsp; emboss = false, &nbsp; &nbsp; &nbsp; &nbsp; -- Properties for a rounded rectangle button &nbsp; &nbsp; &nbsp; &nbsp; shape = "roundedRect", &nbsp; &nbsp; &nbsp; &nbsp; width = w20, &nbsp; &nbsp; &nbsp; &nbsp; height = h20, &nbsp; &nbsp; &nbsp; &nbsp; cornerRadius = 2, &nbsp; &nbsp; &nbsp; &nbsp; fillColor = { default={1,1,0,1}, over={1,0.1,0.7,0.4} } &nbsp; &nbsp; } ) &nbsp; &nbsp; button1.x = board[i][3]; button1.y = board [i][6] &nbsp; &nbsp; button1.anchorX=0; button1.anchorY=0 &nbsp; &nbsp; &nbsp; t = d.newText("X",board[i][3] + w10, board [i][6] + h10, native.systemFontBold,64) &nbsp; &nbsp;&nbsp; &nbsp; elseif board[i][7] == 2 then &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -- Create the widget button2 = widget.newButton( &nbsp; &nbsp; { &nbsp; &nbsp; &nbsp; &nbsp; label = "", &nbsp; &nbsp; &nbsp; &nbsp; onEvent = handleButtonEvent, &nbsp; &nbsp; &nbsp; &nbsp; emboss = false, &nbsp; &nbsp; &nbsp; &nbsp; -- Properties for a rounded rectangle button &nbsp; &nbsp; &nbsp; &nbsp; shape = "roundedRect", &nbsp; &nbsp; &nbsp; &nbsp; width = w20, &nbsp; &nbsp; &nbsp; &nbsp; height = h20, &nbsp; &nbsp; &nbsp; &nbsp; cornerRadius = 2, &nbsp; &nbsp; &nbsp; &nbsp; fillColor = { default={1,0,0,1}, over={1,0.1,0.7,0.4} }, &nbsp; &nbsp; } ) &nbsp; &nbsp; button2.x = board[i][3]; button2.y = board [i][6] &nbsp; &nbsp; button2.anchorX=0; button2.anchorY=0 &nbsp; &nbsp; &nbsp; &nbsp;t = d.newText("O",board[i][3] + w10, board [i][6] + h10, native.systemFontBold,64) &nbsp; &nbsp; end&nbsp; &nbsp;-- &nbsp;----REGISTER WIN------- &nbsp; &nbsp; if board[1][7] == 1 and board[2][7] == 1 and board[3][7] == 1 or&nbsp; &nbsp; &nbsp; board[4][7] == 1 and board[5][7] == 1 and board[6][7] == 1 or&nbsp; &nbsp; &nbsp; board[7][7] == 1 and board[8][7] == 1 and board[9][7] == 1 then&nbsp; &nbsp; &nbsp; &nbsp; print("win") &nbsp; &nbsp; &nbsp; win.text = "X WINS" &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; elseif&nbsp; &nbsp; &nbsp; board[1][7] == 2 and board[2][7] == 2 and board[3][7] == 2 or&nbsp; &nbsp; &nbsp; board[4][7] == 2 and board[5][7] == 2 and board[6][7] == 2 or&nbsp; &nbsp; &nbsp; board[7][7] == 2 and board[8][7] == 2 and board[9][7] == 2 then&nbsp; &nbsp; &nbsp; &nbsp; print("win") &nbsp; &nbsp; &nbsp; win.text = "O WINS" &nbsp; &nbsp; end &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; if board[1][7] == 1 and board[4][7] == 1 and board[7][7] == 1 or&nbsp; &nbsp; &nbsp; board[2][7] == 1 and board[5][7] == 1 and board[8][7] == 1 or&nbsp; &nbsp; &nbsp; board[3][7] == 1 and board[6][7] == 1 and board[9][7] == 1 then&nbsp; &nbsp; &nbsp; &nbsp; print("win") &nbsp; &nbsp; &nbsp; win.text = "X WINS" &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; elseif &nbsp; &nbsp; board[1][7] == 2 and board[4][7] == 2 and board[7][7] == 2 or&nbsp; &nbsp; &nbsp; board[2][7] == 2 and board[5][7] == 2 and board[8][7] == 2 or&nbsp; &nbsp; &nbsp; board[3][7] == 2 and board[6][7] == 2 and board[9][7] == 2 then&nbsp; &nbsp; &nbsp; &nbsp; print("win") &nbsp; &nbsp; &nbsp; win.text = "O WINS" &nbsp; &nbsp; end &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp;if board[1][7] == 1 and board[5][7] == 1 and board[9][7] == 1 or&nbsp; &nbsp; &nbsp; board[3][7] == 1 and board[5][7] == 1 and board[7][7] == 1 then&nbsp; &nbsp; &nbsp; &nbsp; print("win") &nbsp; &nbsp; &nbsp; win.text = "X WINS" &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; elseif board[1][7] == 2 and board[5][7] == 2 and board[9][7] == 2 or&nbsp; &nbsp; &nbsp; board[3][7] == 2 and board[5][7] == 2 and board[7][7] == 2 then&nbsp; &nbsp; &nbsp; &nbsp; print("win") &nbsp; &nbsp; &nbsp; win.text = "O WINS" &nbsp; &nbsp; end &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; end end Runtime:addEventListener("touch", fill)

If I’m getting it right, you can use button:setEnabled() function when clicked.

https://docs.coronalabs.com/api/type/ButtonWidget/setEnabled.html

hey bgmadclown

I am not currently using buttons in the code so am not sure  button:setEnabled() function will work as it stands now.

But you did give me the idea to change the compartment fills to buttons instead of regular rectangles.

I will try this.

Thank You!

Funny thing, looking at the code again, I can’t recall why I said button:setEnabled() since you are not using any buttons. I’m sorry about that.

If you are going to stick to your current solution, you can add an attribute like isActive to the image / rect you are clicking, add a simple if clause to control isActive and when you click it the first time, you can set it to false.

local function handleTouch (event) if (event.phase == "ended") then if (event.target.isActive)then event.target.isActive = false -- change rect to X or O else -- give error end end return true end rect.isActive = true rect:addEventListener("touch", handleTouch)

I added the buttons to the game and it worked out very well.

I will play around with the other code you supplied.

Thanks for your help!!

d = display w10 = d.contentWidth \* .1 h10 = d.contentHeight \* .1 w20 = d.contentWidth \* .2 h20 = d.contentHeight \* .2&nbsp; w40 = d.contentWidth \* .4 h40 = d.contentHeight \* .4 w60 = d.contentWidth \* .6 h60 = d.contentHeight \* .6 w80 = d.contentWidth \* .8 h80 = d.contentHeight \* .8 local widget = require( "widget" ) ----DRAW LINES FOR BOARD local lline = d.newLine(w40,h20,w40,h80 ) lline.strokeWidth = 5 local rline = d.newLine(w60,h20,w60,h80 ) rline.strokeWidth = 5 local bline = d.newLine(w20,h40,w80,h40 ) bline.strokeWidth = 5 local tline = d.newLine(w20,h60,w80,h60 ) tline.strokeWidth = 5 --PLACE BOARD COMPARTMENT DIMENSIONS IN TABLE board ={ &nbsp;&nbsp; &nbsp; &nbsp; {"tl", 1, w20, h40, w40, h20,0,0, true}, &nbsp; &nbsp; {"tm",2, w40,h40,w60,h20,0,0, true}, &nbsp; &nbsp; {"tr",3, w60,h40,w80,h20,0,0, true}, &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; {"ml", 4, w20, h60, w40, h40,0,0, true}, &nbsp; &nbsp; {"mm",5, w40,h60,w60,h40,0,0, true}, &nbsp; &nbsp; {"mr",6, w60,h60,w80,h40,0,0, true}, &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; {"bl", 7, w20, h80, w40, h60,0,0, true}, &nbsp; &nbsp; {"bm",8, w40,h80,w60,h60,0,0, true}, &nbsp; &nbsp; {"br",9, w60,h80,w80,h60,0,0, true} &nbsp; } -- --Notifications --Notify player if match is found or not local win = display.newText("", 0, 0, native.systemFont, 26) win.anchorX = 0 win.anchorY = 0 win:setTextColor(1, 1, 1) win.x = display.contentWidth \* .65 -- Function to handle button events local function handleButtonEvent( event ) &nbsp; &nbsp; if ( "ended" == event.phase ) then &nbsp; &nbsp; &nbsp; &nbsp;button1:setEnabled(false) &nbsp; &nbsp; end end local idx = 0 gameover = false --FILL COMPARTMENT W/ COLOR & "X"/"O" WHEN TOUCHED local function fill (event) &nbsp; if event.phase == "began" then &nbsp;&nbsp; &nbsp; --MANAGE TOUCH ID &nbsp; &nbsp; if event.x \> w20 and event.x \< w80 then &nbsp; &nbsp; &nbsp; if event.y \> h20 and event.y \< h80 then &nbsp; &nbsp; &nbsp; &nbsp; idx = idx + 1 &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; event.id = idx&nbsp; &nbsp; &nbsp; &nbsp; if event.id \>= 2 then &nbsp; &nbsp; &nbsp; idx = 0 &nbsp; &nbsp; &nbsp; end&nbsp; &nbsp; &nbsp; end &nbsp; end --------------------------------------- &nbsp; &nbsp;--MANAGE TURNS &nbsp; &nbsp; for t = 1, 9 do &nbsp; &nbsp; &nbsp; if event.x \> board[t][3] and event.x \< board [t][5] then &nbsp; &nbsp; &nbsp; &nbsp; if event.y \< board[t][4] and event.y \> board[t][6] then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if event.id == 1 and board[t][8] == 0 then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;board[t][7] = 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;board[t][8] = 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;elseif event.id == 2 and board[t][8] == 0 then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;board[t][7] = 2 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;board[t][8] = 1&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end &nbsp; &nbsp; &nbsp; &nbsp; end &nbsp; &nbsp; &nbsp; end&nbsp; &nbsp; &nbsp; end &nbsp; &nbsp; end &nbsp; ------------------------------------------ &nbsp; &nbsp;--FILL COMPARTMENT WITH X/O &nbsp; for i = 1, 9 do&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; if board[i][7] == 1 then &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; -- Create the widget button1 = widget.newButton( &nbsp; &nbsp; { &nbsp; &nbsp; &nbsp; &nbsp; label = "", &nbsp; &nbsp; &nbsp; &nbsp; onEvent = handleButtonEvent, &nbsp; &nbsp; &nbsp; &nbsp; emboss = false, &nbsp; &nbsp; &nbsp; &nbsp; -- Properties for a rounded rectangle button &nbsp; &nbsp; &nbsp; &nbsp; shape = "roundedRect", &nbsp; &nbsp; &nbsp; &nbsp; width = w20, &nbsp; &nbsp; &nbsp; &nbsp; height = h20, &nbsp; &nbsp; &nbsp; &nbsp; cornerRadius = 2, &nbsp; &nbsp; &nbsp; &nbsp; fillColor = { default={1,1,0,1}, over={1,0.1,0.7,0.4} } &nbsp; &nbsp; } ) &nbsp; &nbsp; button1.x = board[i][3]; button1.y = board [i][6] &nbsp; &nbsp; button1.anchorX=0; button1.anchorY=0 &nbsp; &nbsp; &nbsp; t = d.newText("X",board[i][3] + w10, board [i][6] + h10, native.systemFontBold,64) &nbsp; &nbsp;&nbsp; &nbsp; elseif board[i][7] == 2 then &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -- Create the widget button2 = widget.newButton( &nbsp; &nbsp; { &nbsp; &nbsp; &nbsp; &nbsp; label = "", &nbsp; &nbsp; &nbsp; &nbsp; onEvent = handleButtonEvent, &nbsp; &nbsp; &nbsp; &nbsp; emboss = false, &nbsp; &nbsp; &nbsp; &nbsp; -- Properties for a rounded rectangle button &nbsp; &nbsp; &nbsp; &nbsp; shape = "roundedRect", &nbsp; &nbsp; &nbsp; &nbsp; width = w20, &nbsp; &nbsp; &nbsp; &nbsp; height = h20, &nbsp; &nbsp; &nbsp; &nbsp; cornerRadius = 2, &nbsp; &nbsp; &nbsp; &nbsp; fillColor = { default={1,0,0,1}, over={1,0.1,0.7,0.4} }, &nbsp; &nbsp; } ) &nbsp; &nbsp; button2.x = board[i][3]; button2.y = board [i][6] &nbsp; &nbsp; button2.anchorX=0; button2.anchorY=0 &nbsp; &nbsp; &nbsp; &nbsp;t = d.newText("O",board[i][3] + w10, board [i][6] + h10, native.systemFontBold,64) &nbsp; &nbsp; end&nbsp; &nbsp;-- &nbsp;----REGISTER WIN------- &nbsp; &nbsp; if board[1][7] == 1 and board[2][7] == 1 and board[3][7] == 1 or&nbsp; &nbsp; &nbsp; board[4][7] == 1 and board[5][7] == 1 and board[6][7] == 1 or&nbsp; &nbsp; &nbsp; board[7][7] == 1 and board[8][7] == 1 and board[9][7] == 1 then&nbsp; &nbsp; &nbsp; &nbsp; print("win") &nbsp; &nbsp; &nbsp; win.text = "X WINS" &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; elseif&nbsp; &nbsp; &nbsp; board[1][7] == 2 and board[2][7] == 2 and board[3][7] == 2 or&nbsp; &nbsp; &nbsp; board[4][7] == 2 and board[5][7] == 2 and board[6][7] == 2 or&nbsp; &nbsp; &nbsp; board[7][7] == 2 and board[8][7] == 2 and board[9][7] == 2 then&nbsp; &nbsp; &nbsp; &nbsp; print("win") &nbsp; &nbsp; &nbsp; win.text = "O WINS" &nbsp; &nbsp; end &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; if board[1][7] == 1 and board[4][7] == 1 and board[7][7] == 1 or&nbsp; &nbsp; &nbsp; board[2][7] == 1 and board[5][7] == 1 and board[8][7] == 1 or&nbsp; &nbsp; &nbsp; board[3][7] == 1 and board[6][7] == 1 and board[9][7] == 1 then&nbsp; &nbsp; &nbsp; &nbsp; print("win") &nbsp; &nbsp; &nbsp; win.text = "X WINS" &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; elseif &nbsp; &nbsp; board[1][7] == 2 and board[4][7] == 2 and board[7][7] == 2 or&nbsp; &nbsp; &nbsp; board[2][7] == 2 and board[5][7] == 2 and board[8][7] == 2 or&nbsp; &nbsp; &nbsp; board[3][7] == 2 and board[6][7] == 2 and board[9][7] == 2 then&nbsp; &nbsp; &nbsp; &nbsp; print("win") &nbsp; &nbsp; &nbsp; win.text = "O WINS" &nbsp; &nbsp; end &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp;if board[1][7] == 1 and board[5][7] == 1 and board[9][7] == 1 or&nbsp; &nbsp; &nbsp; board[3][7] == 1 and board[5][7] == 1 and board[7][7] == 1 then&nbsp; &nbsp; &nbsp; &nbsp; print("win") &nbsp; &nbsp; &nbsp; win.text = "X WINS" &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; elseif board[1][7] == 2 and board[5][7] == 2 and board[9][7] == 2 or&nbsp; &nbsp; &nbsp; board[3][7] == 2 and board[5][7] == 2 and board[7][7] == 2 then&nbsp; &nbsp; &nbsp; &nbsp; print("win") &nbsp; &nbsp; &nbsp; win.text = "O WINS" &nbsp; &nbsp; end &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; end end Runtime:addEventListener("touch", fill)