mardi 23 février 2021

Kotlin: I want to update an array of letters while the array is out of the "if". How can I keep the update when the array update leaves "if"?

The problem is, that the array will clear itself after leaving the "if" function, and I want to keep it saved, even in the while loop.

while (letters != correct) {

var missedl = arrayListOf("")

        if (word.contains(input)) {

            println("Missed letters: $missedl")

        } else {

            missedl.add(input)
            println("Missed letters: $missedl")

        }
}

This doesn't work either:

while (letters != correct) {

var missedl = arrayListOf("")
missedl.add(p)

      var p = if (word.contains(input)) {

            println("Missed letters: $missedl")

        } else {
            input
            println("Missed letters: $missedl")

        }
}

Aucun commentaire:

Enregistrer un commentaire