mercredi 20 janvier 2016

Call array on array

I am trying to randomize an Array and when I have that Array randomize a value from that Array:

class Board {

var animalArray:[String] = ["beerArray", "duckArray"]
var bearArray:[String] = ["bear", "bear1", "bear2"]
var duckArray:[String] = ["duck", "duck1"]
var chosenArray:String
var chosenImage:String

init () {
    self.chosenArray = ""
    self.chosenImage = ""

}

func randomArray () {

    // Randomize a number
    var firstRandomNumber:Int = Int(arc4random_uniform(1))
    var secondRandomNumber:Int = Int(arc4random_uniform(1)) 

    // Construct a string with the random numbers
    self.chosenArray = self.animalArray[firstRandomNumber]
    self.chosenImage = self.chosenArray[secondRandomNumber] //this part doesn't work

    print(chosenArray)
    print(chosenImage)

    }

}

So I do get a random Array in the chosenArray that is working. When I try to access the Array that was randomized I can't get the value from that Array via a randomizer. What am I doing wrong here?




Aucun commentaire:

Enregistrer un commentaire