-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Better save/load system. #41
Comments
Not sure if you've seen my file management system or my configuration system. But feel free to take a look at JSON or YAML. Yaml is a more simple, cleaner looking configuration type as opposed to JSON, and that's probably what I would recommend for your saving system. If you want to assign me to this issue I'd love to help. And I'd completely understand if you would rather do this yourself! Just lemme know which configuration system you prefer and I can set it all up for you. Even a conversion system to convert the old saves to the new system. |
@BrendonButler Sounds great! If you want,I can give you write-access to the repo so you can commit to it as you wish; getting rid of the need of forking and pull requests :) |
Just let me know ^ |
Whichever way works for you. I don't mind the extra step. Probably prefer it, just in case there's something I try to merge that you would prefer done another way or something. But if you ever need help with any of the issues, just let me know. |
I don't think I can even assign you to to an issue unless you're part of the repo, so I'll just add you :) Don't worry about my preferences, I'm not really picky. Especially when it comes to saving and loading, because any way is better than my current way, honestly. Thanks a ton! I've been procrastinating fixing this for a while. |
I added you as a collaborator. You just need to accept. Commit as you wish :) And if you still prefer the whole idea of merge requests and stuff, you can always just make different branches while you work on whatever, then do a merge request back into master. Big thanks once again! |
@hhaslam11, So I've been working pretty hard on this and I'm almost done (I think). New save files and converting old save files seems to work just fine. The only issue that I'm having is that some settings aren't saving to file (notated by a "// not saving" comment), and the ones that are, are very out of order. (They're formatted, but not put in the order they were set in). I think the issue with the saving has to do with the way my saving method builds trees (maps inside of maps). Shouldn't be a difficult fix. And the out-of-order-ness might just be something small I'm overlooking. Feel free to have a look at the progress: Saves.java This is what a save file currently looks like, (even managed to keep your custom extension): Text-Fighter_Bren.TFsave |
Looks great so far! I do have one question though, in the method |
I love how clean it is now. Even little things like:
instead of doing |
So basically, it sets a key and a value for the data map. The only reason that the set method is so large is that I have it so that you can have child nodes. For example, in Text-Fighter_Bren.TFsave, to get the formatting so that "Health" is indented and directly under "User" you have to have User set to a Map of some sort. Then to access the "Health" variable. You would use the key "User.Health." What that method does is it breaks down the key into an array. Each string in the array is called a node ["User", "Health"], then it iterates through each node in the array and checks to see if the data map contains the current node. If it does, check to see if it is a Map type, if it is, search that map for the next node. If it is not, create all the rest of the nodes and add them to the data map. It's very simple, but very complicated at the same time. If you don't understand or have more questions, feel free to ask! Also, the readBoolean() method was just left in from when I started editing the SaveAndLoad class. xD
|
Ah, I see! |
I just made a new commit, there's a weird ArrayIndexOutOfBoundException being thrown no matter how I change that line of code on line 770. Feel free to take a look, I'm very tired, maybe I'm just overlooking something simple. I'll take a look tomorrow if you don't get a chance to. |
Also, one thing I forgot to mention is that instead of having to worry about what order you set data in. As long as the data is in the data map when the game is saving, it will be formatted and saved to the file. To retrieve data, when the save file is being loaded, it will automatically take all the data from the .TFsave file and store it in the data map. |
I deleted the whole "else" block that contained that so that I can restart from scratch. The block above that works fine. It will save anything that hasnt been saved yet. |
I'm pretty certain that I'm almost done. Saving: Loading: Converting: If you would like, I can create a pull request and we can both try to figure out the remaining issues. Or I can finish it on my own and create a pull request when it's done. It would just be a few more days before it's finished. Unless I run into another issue that I can't wrap my brain around. xD |
sure, go ahead and create a pull request, thanks! I'll merge it on a separate branch so I can continue testing other things while this is still being worked on |
What does for (int i = nodes.length - 2; i > 0; i--) { do? More specifically, why the |
Also, I'm "fixing" things I assume are typos, but I could be wrong because I still don't really understand the code. So I might be breaking more than I'm fixing........ |
Feel free to change any of the keys (ex: "Stats.XP" could be changed to "User.XP" or just "XP", really anything you want. Just make sure that if you change it in one location, you change it in all locations. So just do a search for the key and replace all instances of it. (Should be 2-3 max). Also, feel free to change the order of the "set()" method calls. That way you can organize them and group them however you like. |
Basically what that loop is doing, is looping through each node and setting the previous parent to the current parent (example below). The reason it is -2: To access "third" you would have to subtract 1 from the length nodes[i - 1]. This is already done for us in the loop itself, so we can just call nodes[i]. Okay, so why -2 instead of -1? To set the "third" node, since each node is a map, you would access the "second" node and put the "third" node in it. nodes[i-1].put(nodes[i], mapObject); If that doesnt make sense I will explain later. I'm at work right now. But feel free to keep leaving questions and I will answer when I get out! :) |
Alright, almost a week later I'm coming back to this haha...
For now though, I'm going to do usually helps debug. Copy the class in an entire new project, and minify it so im only working with ~5 variables instead of... a lot. |
not being set at runtime seems to be unrelated.
and printing them out
results in
I can't see any patterns with the variables not being saved.. Maybe I'm overlooking something, because there must be something similar about the three thats not working. |
Derped that up with Let's try this again.
|
@hhaslam11 try printing out the data map. should be something like; System.out.println(data.toString()); and add that to your last comment. |
output was
|
The data doesn't exist in the map and that's why it's returning -1 when you print the value of it. I think I know my mistake, but I could be dead wrong. Will do some testing. |
It has something to do with having 3 nodes... thats the only times it wont save. But sometimes it will save with 3.. always works with two though... |
Also thanks for the diagram, makes sense now |
That was exactly what I was talking about xD The three nodes must be the issue. |
https://gist.github.com/hhaslam11/a30845a543ea1e0abf7e411029b5c033 |
Think i found it. if node[0] has been used before, it wont work.
to
then If that makes sense..... |
That means that the issue lay somewhere in this else block. |
So first thing i did was look for common mistakes.
Now to confirm this was actually the problem.. |
Seems to work great on TextFighter! Guess it was that simple all along... |
AHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHh |
Hmm.. It just crashed when loading, maybe it didnt fix anything (or theres something else wrong) |
Crashed when loading the save file? |
Everything seems to be in the save file though, which wasnt happening before. |
Stacktrace? |
Yeah, when loading the save file
|
did you remember to replace all the data you exchanged for this?
|
That was all in another project i copy-and-pasted. at this point the only thing i modified in the original file was the |
Looks to me like "Settings.Difficulty.Level", "Settings.Cheats.Enabled" are not being saved to the file. Maybe the ">=" fixed some things, but not everything? I'm too tired to figure out this crazy issue xD I'm gonna get some sleep. Hopefully it's something simple! |
Yeah, thats what I'm thinking.. changing |
back to the test file ;)
|
I'm going to get some sleep and continue in the morning (unless you fix it tonight). |
I'm resorting to stackoverflow.com http://stackoverflow.com/questions/38946672/java-not-saving-all-data |
So, just finishing up. Everything seems to be working okay finally (Said that before.). I noticed one comment though, and was wondering about it
Was wonder what exactly would be the purpose of doing this? |
It was just an idea I had to check whether or not save file is newer, current or older. And I did notice one thing with the new set method that guy had. And that's that it doesnt allow you to have multiple nodes that branch off eachother. "First.Second.Third" If you delete your TFSave file and try saving all the data, it wont save any branches. (At least in my testing. I was working onna fix, but had to go to work) Maybe take a quick test to see if it is or isnt workijg for you. |
Not sure what you mean..Seems to work fine for me
test.txt
Maybe I'm misunderstanding what you meant.. |
Mis-clicked, whoops. I dunno. Nevermind then. I copied and pasted his new set method into ModestAPI and did some testing and I didnt get that result :/ will have to do more testing! |
Something way cleaner. Current one is a pain to add things to.. (Use XML?)
The text was updated successfully, but these errors were encountered: