How do I load variables from a file back into Scala? -
i have variables in scala have values written external file in format:
1 2 0 0.5 0.62
this code puts them in file called "myvars.txt":
val pw = new java.io.printwriter("myvars.txt") pw.println(begingamecounter) pw.println(trianglecount) pw.println(trianglescore) pw.println(lives) pw.println(curplayer.getx) pw.println(curplayer.gety) pw.close
how load these variables scala , replace old variables these new variables (for example old variable begingamecounter 0, when load file, want become 1)?
thank you.
you try this:
val values = source.fromfile(pathtofile).getlines.tolist begingamecounter = values(0) trianglecount = values(1) trianglescore = values(2) lives = values(3) currplayer.setx(values(4)) currplayer.sety(values(5))
this of course assumes variable on line consistent.
Comments
Post a Comment