Hello,
I’m working on a strategy game. When the player ends his turn, it switches over to the “computer’s” turn. Understandably, there is a one or two-second delay at this point, as the game logic iterates through a few thousand potential moves and calculates the optimum move. I’m trying to give the player some indication that this is happening, so he can be sure that the button at least registered when he clicked, “End Turn”. Just a simple text display that reads, “Thinking”, along with making the player’s “End Turn” button invisible.
Nothing I’ve tried so far has made this happen. It appears that the program is running the entire AI analysis, and then hiding the “End Turn” button afterward, which is not the order that the commands appear in the code.
Thank you for your thoughts and your help in this matter!
local function computerTurn () local fenceToBuild = false local broonie = {} couldBeMat = {} moveMax = 0 moveToChoose = {} potential = 0 for a1 = 1, #fence do for b1 = 1, #fence[a1] do for c1 = 1, #fence[a1][b1] do broonie = fence[a1][b1][c1] -- Next line checks whether the move is legal if broonie.showing == 0 and checkForAdjacent(broonie) then -- Next line checks whether the move scores any points if tryItOut(broonie) then -- Check whether the move scores more points than other -- moves analyzed so far. potential = testForTiles(false) if potential \> moveMax then nextCBM = #couldBeMat+1 couldBeMat[nextCBM] = {} couldBeMat[nextCBM][1] = potential couldBeMat[nextCBM][2] = broonie moveMax = potential moveToChoose = nextCBM end else -- This trySecondLayer function is where the iteration gets -- really intensive. It is almost exactly the same as this -- "computerTurn" function, so that AI can analyze combinations -- of two moves during the same turn. trySecondLayer(broonie) end turnFenceBack(broonie) end end end end thinkingMsg.isVisible = false -- Turn off the indicator that AI is thinking. for z1 = 2, #couldBeMat[moveToChoose] do buildFence(couldBeMat[moveToChoose][z1]) end endTurn() end local function endTurn() -- Called when human or AI finishes a turn lookForNewLoops(true) -- Check whether the player has scored any points endTurnGroup.isVisible = false -- Make the "End Turn" button invisible -- About twenty lines here. I don't think they affect the process. switchPlayer() -- Changes player from 1 to 2, or vice-versa if player == 2 and compPlayer == 1 then thinkingMsg.isVisible = true -- Should make a "thinking" message visible. computerTurn() -- Begin AI end end