0

Hi I have a game and it has 5 lines of words, and i want to check their validity, and then it flashes up a message saying "WORD: 5 point" or "WROD: Invalid" etc

I have a button with the following code (as you can see i have tried a delay)

 func calcButton() {

    //Do the across calculations and total points
    for i in (0...4) {
        DispatchQueue.main.asyncAfter(deadline: .now() + 5.0) {
            self.acrossCalc(lineNo: i)
        }

        }
}

This then calls this fucntion

func acrossCalc(lineNo:Int) {

    testWord = ""
        wordCheck.removeAll()

        for k in (lineNo * 7...lineNo * 7 + 6)
           {
                if (showLetters[k] != "!") {
                   if (showLetters[k]) != "?" {
                        testWord = testWord + showLetters[k]

                        wordCheck.append(showLetters[k])
                        }
               }
           }
            wordCalc()
    }

and then wordCalc() checks the word and flashes the message.

The problem i have is that it checks all 5 lines instantly, and flashes the message for the last one only.. I need each word checked and message shown, then the next etc....i have tried the above DispatchQueue, but that failed. Maybe i need something elsewhere to allow each word to be checked with enough time to display the message.

Any suggestions please?

Asperi
  • 228,894
  • 20
  • 464
  • 690
Lynxbci
  • 71
  • 7
  • If you want a periodic delay use timer instead of for loop – Teja Nandamuri Feb 04 '20 at 17:22
  • You need to increase the interval for each scheduled task so they don't happen at the same time as explained by [this answer](https://stackoverflow.com/a/43310332/1630618) – vacawama Feb 04 '20 at 17:35

0 Answers0