+ 3
Keeping a variable alive
I've been struggling with this for a while, so I have made a rock, paper and scissor consol based game with a score tracker. It consists out of a couple of diffrent classes, so when ever either the computer or player win the score will go up by one to the respected winner, but it rather reset back to the 0 every time it's called. I know the whole garbage collecter cenario, so is there a way to keep the score alive or is there a diffrent way I can achieve this, any ideas will be welcome.
8 Antworten
+ 4
@aditya. Thank you. it's running perfect.
+ 3
All console based program or any simple program will run on ram. And when you close program it reset to 0. you have to data in file like txt or in SQL. And then you can get it right. and you can show your program code, I will improve a little bit. Above explanation is about leaderboard. I thick their is a logical error in your code.
+ 3
@aditya. I followed you, if you can follow me and check the RockPaperScissor code then you can have a look at it. Keep in mind I coded that with diffrent classes is mind, so I had to push it all into one class (not that I really think it'll make a difference in the end result). This is the easiest way I can imagen for you to help me.
+ 3
Hey I could not post your updated code as answer, yeah I have correct it and it is working fine. I have posted in my code section please check it. And copy your code Than I will remove that.
+ 3
Then I remove it.
+ 2
Thank you for the reply, well the score doesn't need to stay there when I re-open the file, it's only being used for the time that the program is running.
+ 1
after your program killed, the memory that used for storing your application data will be released too
you need to store that score into a file, n everytime your program run, you need to read the file to reload the last score you save there
it isn't about garbage collector. it's about saving data to disk
+ 1
Please show your code I think there is an logical error