ios - Trouble loading data from arrays -


in swift have array follows:

var storedlevels = [     1:[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,        0, 6, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 7, 0,        2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],      2:[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,        1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1] ] 

i need able load array storedlevels[1] variable, loop through values in variable.

at time have working, have explicitly set 1 x in storedvalues[x] loop through code.

this function i'm using:

func loadlevel(level: float) {         var x: int = 0         var y: int = 0          let blocks = storedlevels[1]          var i: cgfloat = 0; <= (gblockcounty); += 1 {             y = int(i)             var i: cgfloat = 0; <= (gblockcountx-1); += 1 {                 x = int(i)                  var blockcounttotimes: cgfloat = cgfloat(y)-1                 if blockcounttotimes < 0 {                     blockcounttotimes = 0                 }                 let blocknumber = (gblockcountx * blockcounttotimes) + cgfloat(x)                  if let block = blocks?[int(blocknumber)] {                     addblocktogrid(cgfloat(block), x: cgfloat(x), y: cgfloat(y))                 } else {                     addblocktogrid(1, x: cgfloat(x), y: cgfloat(y))                 }             }         }     } 

how can make let blocks = storedlevels[1] use value passed function (level: float) replace 1?

storedlevels dictionary of type (int, [int]), not array. don't know why need have key (and hence makes dictionary). fine:

var storedlevels = [ [0, 0, 0, ...], [1, 1, 1, ...] ] let blocks = storedlevels[int(level) - 1] 

now dictionary: key of type int level float. can there level 1.5? if want go dictionary paradigm, cast level int:

let blocks = storedlevels[int(level)] 

Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -