-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Add a saving demo that uses custom resources #924
base: master
Are you sure you want to change the base?
Add a saving demo that uses custom resources #924
Conversation
35d0178
to
103461d
Compare
103461d
to
edd252a
Compare
Points 3 and 4 can be fixed by implementing your own resource format (not |
In addition to what was said above, we already have a saving and loading demo that showcases both ConfigFile and JSON. If we were to demonstrate another method of saving and loading, I think it'd be better to add to that demo than to make another one. |
Hi @dalexeev, thanks so much for taking the time to review my demo and provide helpful comments! I'll respond to each of your points. Feel free to reply to me here or on RocketChat, whichever you prefer 😄
This is the first time I've realized that this was an option. The class reference for
Thanks for the feedback @jtnicholl :) Funnily enough, I didn't realize we had that demo until I was drafting this PR, 😆 . Should we link to this demo in the current saving tutorial documentation? I don't mind scraping this demo and building on top of that one (creating it gave me an excuse to learn about tile maps and collisions 😄), but having looked at that saving and loading demo now, I find it perhaps a little too simple. It doesn't provide any guidance on how to approach any of the potential pain points 2.a, 2.b, and 2.c I mentioned above. |
I don't really the issue. It demonstrates the features it's meant to as simply as possible, that's generally what we want from these demos.
What exactly is "time sensitive" data? If you mean data that changes every frame, there's nothing special about it, the enemy positions in the existing demo change every frame and they are saved just the same as anything else.
You can just save a NodePath.
This is a bit more complicated, but not much. You can save arrays and dictionaries, including nested ones. You could also add more variables with a prefix or in a ConfigFile section. None of this is difficult to figure out once you know how the saving systems work, not to mention the demo does use arrays of dictionaries. |
Thanks for the feedback :) I think overall you both have convinced me it makes more sense to build on the previous demo rather than use this one, but I do still have some thoughts on how the previous demo could be improved.
Fair point
That is of course true, but I would argue that this may not be obvious for people new to Godot or game dev. The naive thing to do would be saving the node itself. When users find that doesn't work, they might not know what to do instead. That said, for the sake of keeping the demo simple, maybe the tutorial can just mention this in writing.
Fair point about the demo having arrays of dictionaries. One concern I have with the current demo's code is that the saving scripts are tightly coupled to the details of the player and enemies. I think a good demo should help communicate best practices, I'd like to modify the saving code to follow a pattern closer to the one I used in my code. The current demo saves everything in one monolithic script: var save_dict = {
player = {
position = var_to_str(player.position),
health = var_to_str(player.health),
rotation = var_to_str(player.sprite.rotation)
},
enemies = []
}
for enemy in get_tree().get_nodes_in_group(&"enemy"):
save_dict.enemies.push_back({
position = var_to_str(enemy.position),
}) I think we could set a better example be writing it more like var save_dict = {
player = player.to_dict(),
enemies = []
}
for enemy in get_tree().get_nodes_in_group(&"enemy"):
save_dict.enemies.push_back(enemy.to_dict()) With appropriate In summary, I'm happy to stick with the previous demo with a few modifications. In the written tutorial, I'd like to link to the demo and include a sentence or two about saving node references using node paths. What do you think about this approach? |
I'd agree if this were part of a university course or something, but it's not. Anyone using this already knows how to program, and hopefully knows good practices too. |
Lol :) I definitely agree that one can go overboard when it comes to showing "best practices", but changing to Thoughts? |
Hi folks! Thanks again for your feedback on my demo. I've paused working on this in favor of working on a high-level saving API inspired by the high-level multiplayer API. @dalexeev @jtnicholl I'd love to hear if you have any feedback on the API draft so far: godotengine/godot-proposals#7041. |
This demo shows how a game can be saved using custom resources. It will be referenced in an upcoming addition to the documentation tutorial on saving games.
This demo will be used to help address issue godotengine/godot-docs#7348, which relates to the tutorial https://docs.godotengine.org/en/stable/tutorials/io/saving_games.html.