I am using a function to create a 6 element Boolean Array. I am using the array.component1() function in an if statement to turn the color of a textView object Green. Seems to work great for calling .component 1 thru 5, but I get an error trying to call array.component6(), and I don't understand why.
internal var endArray = setEnd(totLine, totTurn, startTurn)
resultTextView1.text = "A"
if (endArray.component1()) resultTextView1.setTextColor(Color.GREEN)
resultTextView2.text = "B"
if (totLine<2) resultTextView2.visibility = View.GONE
if (endArray.component2()) resultTextView2.setTextColor(Color.GREEN)
resultTextView3.text = "C"
if (totLine<3) resultTextView3.visibility = View.GONE
if (endArray.component3()) resultTextView3.setTextColor(Color.GREEN)
resultTextView4.text = "D"
if (totLine<4) resultTextView4.visibility = View.GONE
if (endArray.component4()) resultTextView4.setTextColor(Color.GREEN)
resultTextView5.text = "E"
if (totLine<5) resultTextView5.visibility = View.GONE
if (endArray.component5()) resultTextView5.setTextColor(Color.GREEN)
resultTextView6.text = "F"
if (totLine<6) resultTextView6.visibility = View.GONE
if (endArray.elementAt(6)) resultTextView6.setTextColor(Color.GREEN) //NOT WORKING
fun setEnd(totLine: Int, totTurn: Int, startTurn: Int): Array<Boolean> {
//internal var totLine: Int = 4 // total no of lines
//internal var totTurn: Int = 2 // no of turns
//internal var startTurn: Int = 1 // which turn starts first
var textA = false
var textB = false
var textC = false
var textD = false
var textE = false
var textF = false
var totLtr: Int = totLine / totTurn // no archers per line
if(startTurn==1) {
if (totLtr == 1) textA = true
if (totLtr == 2) {
textA = true
textB = true
}
if (totLtr == 3) {
textA = true
textB = true
textC = true
}
}
if(startTurn==2) {
if (totLtr == 1) textB = true
if (totLtr == 2) {
textC = true
textD = true
}
if (totLtr == 3) {
textD = true
textE = true
textF = true
}
}
if(startTurn==3) {
if (totLtr == 1) textC = true
if (totLtr == 2) {
textE = true
textF = true
}
}
return arrayOf(textA, textB, textC, textD, textE, textF)
}