Brandy Geeks Brandy Geeks - 1 year ago 114
Scala Question

Update List with Loop Arguments Scala

I'm trying to create slot game with scala programming, I thought scala is pretty much like javascript which could create new Array or new something else with function.

Please suggest me what to do with this code:

import scala.util.Random
import scala.math

val randSymbol = List(1,2,2,3,3,3,4,4,4,4,5,5,5,5,6,6,6,6,6,6,7,7,7,7,7,7,8)
val _finalSymbol = List(List(0,0,0,0,0),List(0,0,0,0,0),List(0,0,0,0,0))
var i:Int = 0
var a:Int = 0
for (i <- 0 to 2){
_finalSymbol(i) = new List
for (a <- 0 to 4){
var iRandIndex = floor(Random.nextInt() * randSymbol.length).toInt
var iRandSymbol = randSymbol(iRandIndex)
_finalSymbol(i)(a) = iRandSymbol

I'm using IntelIJ and I saw that
is not able to read new List and updating the current list of _finalSymbol, also can I use
function when
is not equal to some other var? let say
var result

Answer Source

Try something like this:

val _finalSymbol = (0 to 2) map { _ => Random.shuffle(randSymbol).take(5) }

And do yourself a favor: buy a scala book. It's not javascript. At all.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download