This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

serializing doesn't work  RSS feed

 
Adam Major
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a simple tetris game, and I want to add a save game and a load game method. I used serialization to save the board(which is an array), and it creates the file successfully. When I load the gamefrom the file, nothing changes. The code runs fine, but it doesn't do what I want. Here is the questionable part:
 
Rob Spoor
Sheriff
Posts: 21087
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ItDoesntWorkIsUseless. What should it do, and what does it do instead?
 
Paul Clapham
Sheriff
Posts: 22471
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't understand why the loadgame() method takes a parameter. Perhaps what you wanted involves that parameter in some way... but the code you have there just ignores whatever you pass in from the calling code.
 
Adam Major
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The parameter of the loadgame should be the current board which will be overwritten by the input file. After saving and loading the texts are written on the screen correctly and the game continues. The actual board doesn't change.
 
Paul Clapham
Sheriff
Posts: 22471
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, no, that's because parameters are passed by value in Java. Since you return the board as the value of the method, whatever calls that method should make the returned value be the current board.
 
Adam Major
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank You! That was the solution.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!