Very nice tutorial, thank you for making this! Especially appreciating: Cut right to the point, no rambling and good code style to understand for a beginner like me.
This is a great tutorial! Thank you so much! I am so inspired to continue learning python and pygame after this video. Wish you success in your future.
@@discotrain173 two big things: pickle and schema. Pickle is easy to get started with, but has big caveats (that other people have discussed at length). The other problem is schema: as you ship new versions of your game, the exact data you save may change, and you want to make sure that old saves continue to load in new versions. (I don't mean sequels, I just mean patches.) However, these are only really concerns if you actually ship a game. If you're just looking to quickly add saving to a demo, prototype, experiment, academic exercise, etc, in my opinion this is plenty fine.
@@discotrain173 Ok, so Pickle has two major problems: security and schema. First: security. Unpickling is basically code execution. A crafted pickle can do anything your program is allowed to do: read files, write files, talk to servers, download and run programs, mess with your game internals, anything. Second: schema. I've used this term a few times; it's basically the shape of your data. Pickling rely on the shape of your classes to define their schema. Worst, schema mismatches won't happen when you load the game, they'll happen somewhere else when whatever actually tries to use that data. So if you fix a bheavior by adding an extra flag to an NPC, and that flag isn't in an old save, when a player loads it, the game will crash when the NPC AI goes and looks for the flag. None of this really matters when the expected playerbase is youself--you trust yourself, and you know if it goes funky, just delete your save. But if you ship and patch a game, these caveats will make your players Have A Bad Time.
Looking forward to study your Shader tutorial. Kind of a shame you only have 5 tutorial videos for pygame. Please make more! I am currently trying to learn python and OOP by coding the basics for an imaginary pygame project. So far I have learned and implemented a state stack manager, menu system, delta time, screen size config and now your save load manager. Next steps will be a little more specific to my game idea: Isometric hexagon grid and lighting system with blending and masks. I am really enjoying the journey so far, good luck on yours!
this is a great but totally useless in a real pygame development, because you cant serialize pygame.surface, and most of our implementation are done using sprite and surface. It means, that you need to "de-serialize" each object and use a constructor to rebuild the graphics. This can work, but this is a deep change, and if you do so,many others python modules wont work with pygame any more. I believe the best is to rewrite the save and open, from your classes, instead of using Pickle
Hi this is amazing vido and also for anyone wantinga pit more simpler version import turtle from turtle import * import tkinter as tk score=0 clicks=0 a=turtle.Turtle() a.ht() a.penup() a.goto(-350, 300) a.write(f"Score: {score}", font=("Arial", 21, "normal")) b=turtle.Turtle() b.ht() b.penup() b.goto(-360, 220) b.write(f"Clicks: {clicks}", font=("Arial", 21, "normal")) def tapping(x, y): global score, clicks score+=10 clicks+=1 a.clear() a.write(f"Score: {score}", font=("Arial", 21, "normal")) b.clear() b.write(f"Clicks: {clicks}", font=("Arial", 21, "normal")) turtle.listen() turtle.onscreenclick(tapping) def save(): global score, clicks file=open("save.txt", "w") file.write(f"score: {score} ") file.write(f"taps: {clicks} ") button=tk.Button(text="Save", command=save) button.pack() def load(): global score, clicks a.clear() b.clear() file=open("save.txt", "r") ht() penup() goto(-350, 300) write(file.read(), font=("Arial", 21, "normal")) button2=tk.Button(text="Load", command=load) button2.pack() turtle.mainloop() You can ofcorrse remove the turtle and add whstever python modlua u want i just made it and there isnt any errors as i see i hope it helps and if you hsve any questions feel free to ask :)
Very nice tutorial, thank you for making this!
Especially appreciating: Cut right to the point, no rambling and good code style to understand for a beginner like me.
Dude you are amazing! your way of explaining beats an adult any day!
This is a great tutorial! Thank you so much! I am so inspired to continue learning python and pygame after this video. Wish you success in your future.
Wow what a great tutorial. Great job explaining everything!
That's a pretty solid tutorial! I wouldn't consider this suitable for a shipping game, but as a first save system this is a great starting point.
What do you think would be more suitable save system for a game you're shipping in pygame?
@@discotrain173 two big things: pickle and schema. Pickle is easy to get started with, but has big caveats (that other people have discussed at length). The other problem is schema: as you ship new versions of your game, the exact data you save may change, and you want to make sure that old saves continue to load in new versions. (I don't mean sequels, I just mean patches.)
However, these are only really concerns if you actually ship a game. If you're just looking to quickly add saving to a demo, prototype, experiment, academic exercise, etc, in my opinion this is plenty fine.
@@JamieBliss what other big caveats are there besides if you want to make patches? (I'm a pickle noob)
@@discotrain173 Ok, so Pickle has two major problems: security and schema.
First: security. Unpickling is basically code execution. A crafted pickle can do anything your program is allowed to do: read files, write files, talk to servers, download and run programs, mess with your game internals, anything.
Second: schema. I've used this term a few times; it's basically the shape of your data. Pickling rely on the shape of your classes to define their schema. Worst, schema mismatches won't happen when you load the game, they'll happen somewhere else when whatever actually tries to use that data. So if you fix a bheavior by adding an extra flag to an NPC, and that flag isn't in an old save, when a player loads it, the game will crash when the NPC AI goes and looks for the flag.
None of this really matters when the expected playerbase is youself--you trust yourself, and you know if it goes funky, just delete your save. But if you ship and patch a game, these caveats will make your players Have A Bad Time.
@@JamieBliss ok I see. But what would you use instead of pickle?
Looking forward to study your Shader tutorial.
Kind of a shame you only have 5 tutorial videos for pygame. Please make more!
I am currently trying to learn python and OOP by coding the basics for an imaginary pygame project.
So far I have learned and implemented a state stack manager, menu system, delta time, screen size config and now your save load manager.
Next steps will be a little more specific to my game idea: Isometric hexagon grid and lighting system with blending and masks.
I am really enjoying the journey so far, good luck on yours!
Actually more useful than I thaught
insane code. Its so usefull. you can really use it anywhere. Thanks for this video
Excellent tutorial, thanks a lot!
absolutely love the video! thank you
Glad you enjoyed it!
Thx! Def gonna use it a lot.
thanks! but could you also use f-strings next time because the text+variable+text+variable is killing me
When I try to make an account on Pygame it says disabled, does anyone know how to fix this?
That VS Code theme is giving me an aneurysm
12:27
wow thanks
Thanks kid
Is it just me or the person explaining this is a child?
A child better than me in coding now i see myself more useless now
yup lol
How old are you 🤔
15
Omg so brilliant
this is a great but totally useless in a real pygame development, because you cant serialize pygame.surface, and most of our implementation are done using sprite and surface. It means, that you need to "de-serialize" each object and use a constructor to rebuild the graphics. This can work, but this is a deep change, and if you do so,many others python modules wont work with pygame any more. I believe the best is to rewrite the save and open, from your classes, instead of using Pickle
12:
Hi this is amazing vido and also for anyone wantinga pit more simpler version
import turtle
from turtle import *
import tkinter as tk
score=0
clicks=0
a=turtle.Turtle()
a.ht()
a.penup()
a.goto(-350, 300)
a.write(f"Score: {score}", font=("Arial", 21, "normal"))
b=turtle.Turtle()
b.ht()
b.penup()
b.goto(-360, 220)
b.write(f"Clicks: {clicks}", font=("Arial", 21, "normal"))
def tapping(x, y):
global score, clicks
score+=10
clicks+=1
a.clear()
a.write(f"Score: {score}", font=("Arial", 21, "normal"))
b.clear()
b.write(f"Clicks: {clicks}", font=("Arial", 21, "normal"))
turtle.listen()
turtle.onscreenclick(tapping)
def save():
global score, clicks
file=open("save.txt", "w")
file.write(f"score: {score}
")
file.write(f"taps: {clicks}
")
button=tk.Button(text="Save", command=save)
button.pack()
def load():
global score, clicks
a.clear()
b.clear()
file=open("save.txt", "r")
ht()
penup()
goto(-350, 300)
write(file.read(), font=("Arial", 21, "normal"))
button2=tk.Button(text="Load", command=load)
button2.pack()
turtle.mainloop()
You can ofcorrse remove the turtle and add whstever python modlua u want i just made it and there isnt any errors as i see i hope it helps and if you hsve any questions feel free to ask :)