#.data?

1 messages · Page 1 of 1 (latest)

spiral axle
#

Was looking through a few tutorials about save and loading, and one of them caught my eye , it seemed to work but it relied on a file type with '.data'. tried but, found nothing. And there's two answers im happy to receive:
does .txt also work for handling saves?
and if not: How does one do a '.data' file

i know some games use txt files for data handling but i want to be safe whatever i do won't break the game like a twig

tender summitBOT
vestal vessel
#

You can name a file .data if you want. How to read and write the file is up to you. But in practice if you are putting information in that file in json, yaml, tres format, it’s helpful to give the file a name which reflects that.

spiral axle
#

no no

#

the file type is '.data'

#

im wondering how tf im meant to do that
either that or :
does a .txt file also work

vestal vessel
#

You mean extension? untitled.data?

spiral axle
#

yes- that sorry

vestal vessel
#

That’s what I mean too

spiral axle
#

between a .data extension or a .txt extension...

spiral axle
#

Does a .txt work fine or ?

vestal vessel
#

I think neither .data or .txt is a good choice because neither one tells me how the data is saved

spiral axle
#

right

vestal vessel
#

If you’re storing your data in json, use a .json file. Godot resources, a .tres file

spiral axle
#

im doing neither

#

im just doing a dictionary

#

and saving the dictionary state

vestal vessel
#

How is that written?

spiral axle
#

var savefile = FileAccess.open("res://data/savefile.txt", FileAccess.WRITE)

#

and then on save you store var

#

and on load you do

#

'dictionary = savefile.get_var()

spiral axle
#

i could do a json method but i'd need to find the method for it

#

Rn im wondering abt just doing it with a raw dictionary

vestal vessel
#

Ok so you’re using godot’s serialisation format, which doesn’t have a canonical name or extension as far as I know. Name it whatever makes it clearest for you what the file is for. Could be .txt, .data, .vanilla

#

The file’s name doesn’t change its contents, it’s just a bit of information about what the file is for and how to use it

spiral axle
#

ig i'll do .txt then since it wont physically let me name it anything else

vestal vessel
#

What’s clunky about it?

spiral axle
#

Well,im also operating with the dialogic plugin , and when i loaded back in , it played the music and didnt stop even if i returned to menu

#

it was

#

weird

vestal vessel
#

Doesn’t sound like something a file extension can do

spiral axle
#

fair point-

#

if changing it to a json method would do anything

#

unfortunately couldnt replicate the whole 'music persisting through where it shouldnt' bit

grizzled grove
#

first mistake i spot is that you put your save file in res://
you shouldn't do this as you can not write to this folder once the project is running, it's only good for files you only, and ever want to have as READ only

the correct root of the path should be:
user://

You can find more on that here: https://docs.godotengine.org/en/latest/tutorials/io/data_paths.html

On top of that, it's better to copy the code and paste it here then to record a video, as it's easier to read and help you out, unless the video provides extra details

Is the Data. class something built in from Godot? I can't find it back or is this something you created?

#

As for file extensions, it's usually suggested to not use an extension like .txt for saving 'save files' but in the end, it's just a extension, what ONLY really matters is how you handle this file in your program, you could save valid JSON structure in a .txt file and just parse it fine in godot, it's just misleading. But since you are learning right now I highly suggest reading up on JSON, and trying to get it to work in this format.

spiral axle
#

I'll get the code as soon as i can

#

although i already removed all of the save file related code and im back to square 1 of just using dialogic's built in, but i still remember how the code was like so.

#

n aye, I'll check up on Json

grizzled grove
spiral axle
#

oh , I don't think he did for that one.. he just kinda said "yeah we'll save it to this .data file"
and "so we'll rename the json file back to .data"

grizzled grove
#

How far in the video did you get

#

I know its a longer video

#

But as discussed yesterday its better to take the time, and listen to what the dude has to say instead of rushing in

spiral axle
#

Right uhh, im on dictionaries

#

completed the dictionaries chapter, to be specific

#

or rather

#

was.

#

what i did is basically see if something fit my needs and acted on it.
So, checked simple "nope"
skipped Json because i figured that wasn't what i wanted, and watched the dictionaries chapter. and acted on that

grizzled grove
#

How can you know what fits your needs if you dont know what everything is

#

You gonna end up taking so much more time for everything you want to do, if you dont take a breather from time to time to read/watch something all the way trough

spiral axle
#

fair point

#

just waiting for someone to respond irl so i can buy somethings, but afterwards I'll like, keep up both with the video and keep this thread posted up on the code

grizzled grove
#

Don't feel like you have to watch this video to learn about the topic, if you don't like listening to this guy and it's the reason you stopped watching that is fine. Don't force your self, but just do it good that's all, don't half ass it, if you decide I am gonna watch this, watch it trough, reading the docs, asking questions to chatGPT, not why does it not work, but let him explain the docs or ways of doing it, using another video, using a demo project : https://github.com/godotengine/godot-demo-projects/tree/master/loading/serialization are all fine methods of learning

GitHub

Demonstration and Template Projects. Contribute to godotengine/godot-demo-projects development by creating an account on GitHub.

spiral axle
#

But i'll try all of these

#

i did consider 'swapping projects and coming back later' but idk, part of me kinda wants to sit down and finish this visual novel first

#

so i probably know why the code fucked up at this point thanks to your insight, BUT , i'll say what i did anyways:

So i made a folder called data
And in that folder made a txt file 'savefile.txt'

in my global, autoload node called 'data'
i had
var file = FileAccess.open("res://data/savefile.txt", FileAccess.WRITE)

and
var save_data : Dictionary = {
"location" = "scene"
}

and the rest of the code i put in the save ,load, and load game buttons (the diff between load and load game is that one belongs to a pause menu canvas layer scene and one is on the title screen, but functionally they're almost the same)

For saving i did:
on pressed
Data.save_data["location"] = get_tree().current_scene.name
Data.file.store_var(Data.save_data)
Data.file.close()
Dialogic.Save.save("slot")

And dialogic's built in save, can save dictionaries but you have to put extra code in for it, this one, in theory , should only be keeping track of the current active dialogue, were there to be any.

then the load buttons were
On pressed
var file = FileAccess.open("res://data/savefile.txt", FileAccess.READ)
Data.save_data = file.get_var()
file.close()
Dialogic.Save.load("slot")
if get_tree().current_scene.name != Data.save_data["location"]:
get_tree().change_scene_to_file("res://scenes/" + str(Data.save_data["location"]) +".tscn")

And load game is identical except it doesn't have the if clause, its just 'change scene to location.tscn'

and it worked mostly fine, but some things were just..clunky..No crashes, but, red errors that scared me a little, save games still not necessarily working across closing and re openings of the game, and some sound related bugs.

spiral axle
grizzled grove
#

but i need the official dialogic discord to answer something for me for it

You have a theory, yet I don't understand why they must answer, why are you just not testing it yourself?

spiral axle
#

Im a bit scared to hard commit to something jsut for it to fail, since changing one thing could result in a lot of time changing other things to work around it, + i wanna make sure i know how , since im not even fully sure how to do things.

one thing i could test but would be extremely time intensive:
instead of a dictionary, store all the variables in dialogic's built in variables system, which the built in save function actually naturally accounts for.

the other is. Like i said, the dialogic built in save can store Dictionaries, but im not sure if i need to do something to access it or not.
"Dialogic.Save.save("slot",false, Dialogic.Save.ThumbnailMode.NONE, Data.save_data)"

but if i close and re open it doesnt actually seem to remember what Data.save_data was at the time, and so im wondering if theres maybe something extra i have to do, or if theres any way to communicate with the file that Dialogic is storing this info, if so then it should be possible, but theres nothing in documentation

#

the big main factor is mostly fear though

#

The end result of all of this, is to learn and be able to work with this at a professional level.
But i also want to upload these as games for people to play .
And if i do , lets say, a catastrophic fuck up, im not sure i'd have it in me to start from scratch or go through a monumental fixing phase just for that

#

so i generally

#

like to first make sure i know what im gonna be doing

#

and that it wont be too wild of a curve ball

#

and then i get my hands dirty

grizzled grove
#

Are u using version control? Git?

spiral axle
#

not github

#

i tried version control but it didnt let me bc i didnt have a version control plug in

#

at least from what godot itself said

grizzled grove
#

Your highest priority should be to have this set up

#

Its funny you trying so vae progress for the player but ur not even saving ur own progress

#

If tomorrow ur pc breaks

#

U can just download it again

spiral axle
#

fair

grizzled grove
#

If u fk up catastrophic today, you revert back

spiral axle
#

any readily available in the asset library or do i have to find it by searching

grizzled grove
#

After that, play around with it, feel comfy with it

#

Then test your idea

spiral axle
#

alright

grizzled grove
spiral axle
#

oh when you said git i thought you meant github
is there sum called git that acts as version control?

grizzled grove
#

Git is like the tool, while github is the one that let us use the tool

#

Like mail in Gmail

#

Like p* in p*hub

#

I got timed out for that second like for 10 minuts btw

#

But also again very many guides out there to help u get started

#

Downloading github desktop is the easiest

spiral axle
spiral axle
#

actually i can also probably google about version control

#

admittedly still scared of course but.
Version control
Then Json saving

#

and from there , it should be as easy as just.. doing the story/drawing the scenes..

#

looks like im also gonna be using Git lol

spiral axle
#

the fuck is anchorpoint

warm sphinx
warm sphinx
#

Would say to just use normal Git unless you have a good reason to do something different

spiral axle
#

alright

#

So im assuming git is..something on the asset library then?

#

i got the desktop github app

#

a github account

warm sphinx
#
  • Git is a command-line app used in software development for version control
  • Github is a website centered around the usage of Git, but is not associated with Git
  • Github desktop is a GUI app that makes using Git easier, allowing you to click buttons instead of typing commands on the command-line
spiral axle
#

So.. i imagine i dont need to download a git app or..?

#

bit confused on that front

warm sphinx
#

"Version control" just means that you can make checkpoints that you can return to, and "merge" different branches of code

warm sphinx
#

so at the very least you would have to download the command-line Git tool

#

BUT

spiral axle
#

i have github n i have godot.
that is about it-

warm sphinx
#

If you don't want to use it from the command-line, a GUI app like github desktop is good

#

Github desktop comes with everything you need

spiral axle
#

alright bet

warm sphinx
#

I could give a quick crash course on this over VC if you're available for that

spiral axle
#

could it be later on ? Or

warm sphinx
#

I'm thinking now!

#

About to go sleep but I have a little bit

#

If now doesn't work, we can schedule for later

spiral axle
#

alright then

#

i mean

#

what would YOU prefer.
if you'd rather sleep we can schedule later n i can see how much i can gather from tutorials

warm sphinx
#

I prefer now! But I will take a few min to brush my teeth, so brb

#

should be good in... 5min

spiral axle
#

sure

spiral axle
#

só, do i need to make a text file myself, or can i just name something that doesn't exist and godot will create it?

spiral axle
#

yknow what maybe i dont skip chapters next time actually- (this is from the tutorial video)

#

the consequences of my actions catch up to me once more

pastel nest
#

Oh nvm

spiral axle
#

Nah, but im gonna try Json

spiral axle
#

i. prob could cclose the thread and make a new one asking abt it..But, idk im doing questions so often that im not sure if it can reach the point of becoming too much.
So it feels safer to just stay here

pastel nest
pastel nest
spiral axle
spiral axle
#

except this time i'll actually watch the video through before actually doing it-

pastel nest
#

Yep! Just remember to do filePath.close() or some weird stuff will happen

#

As I've found the hard way xD

spiral axle
#

tbf weird stuff was happening even when i did filepath close
but then again that was when i was doing res:// so

pastel nest
#

Yeeeah don't do res:// do user://

#

Though I think someone said that already

spiral axle
#

yup

#

thats why i said its prob the reason it was being fucky

pastel nest
#

Yeeee

#

Also another thing with Json is that it sorts your data alphebetically, so when stringifying it I always do
json.stringify(yourData, "\t", false)
To turn off the sort, in case you sort your data differently and need to loop through it for whatever reason

#

I never saw that in any tutorials when i learned and it tripped me up a lot

spiral axle
pastel nest
#

Ahh yee fair. I sort cause I have a rpg with a loooot of materials I have to loop through when the inventory loads

spiral axle
#

and since im mostly in a testing phase (i wanna make sure everything works before i start doing actual story and art) theres just. not a lot of variables going around

pastel nest
#

That's fair yeah

pastel nest
#

Lmk if you have any questions or need help with Json, I've worked with it quite a bit in the past

spiral axle
#

the video is..an hour long, so it'll take a little! but, for sure

spiral axle
#

i mean..he finished the json part..And now he's going on through resources..even after the resource chapter so im not sure...if there is a point to watching it fully- but- maybe-

#

i'll say

#

im also tempted to just try dictionaries again but
Both times i tried i fucked up so
maybe i do just try Json fr

#

wait..okay..i think i can see one mistake on my part

#

i cant quite tell if the default state should be read or write..considering...
this is a global node thats gonna be referenced by the save and load buttons

#

i mean , could maybe move these vars to the buttons themselves but then idk if i can reference them from anywhere

pastel nest
#

I wouldn't declare the variable as an open file, id declare the path then declare the state in ready or process

#

Json and dictionaries kind of go hand in hand

spiral axle
#

oh?

#

well i dont really have any

#

funcs..

#

On the global node

#

just the scene changer one

#

so im not sure..

pastel nest
#

Global?

spiral axle
#

Autoload

pastel nest
#

Do you have an overarching manager node in your scenes? Like gameplay scenes like levels, stages, etc..

spiral axle
#

though since this is a visual novel, this really is more of a

#

glorified variable storage

#

its just so that any scene can have access to the variables that were checked in any other scene

pastel nest
#

Ohh

#

Okay so in that case, I would recommend saving and loading rather than an autoload. And then you can put the save code in a function in either a resource or blank node, and then instance that node where you need it.

spiral axle
#

its just

#

ok its a bit weird but

spiral axle
#

and then

#

save and load are part of the same scene, PauseMenu, a canvas layer.

and load_game is exclusive to the title screen

#

and what i did before was essentially

#

i estabilished the variable on data manager.
and then just did all of the usual code in the buttons themselves, referencing the data manager's dictionary

pastel nest
#

Okay so data is your manager, and handles saving and loading correct?

#

Ohh wait I see it. You have a saving script and loading script as separate things

spiral axle
#

Data is my manager, and has the dictionary containing all of the data, and is set to auto load

then.
pausemenu is a scene with a save button child, and a load button child
and Menu is the title screen, with a load_game child node

spiral axle
#

( i fully realize how stupid this all is but i was scared)

#

((this was the safe approach))

pastel nest
#

Okay so your storing saving and loading code in canvas layers
For a visual novel game idk if it matters as much, but that means if you ever wanted to save or load anywhere else you'd have to copy and paste those functions

spiral axle
#

instantiate it

#

:D

pastel nest
#

Will those canvas layers be in every scene?

#

If so then ig this works

spiral axle
pastel nest
#

But the data being an autoload is what's mainly tripping me up

spiral axle
#

if its not auto load, then i cant interact with the dictionary at all unless i put the scene on my scenes

#

it being an autoload means i can now just sorta go

#

Data.save_data["variable"] = thing

pastel nest
#

Yeee I understand
My only issue with that is if there's ever a time you don't need it in a scene, it's loaded anyways and taking up space

spiral axle
#

after all, if its not there, then when you save the game , all of the stuff you did wont be recorded..

pastel nest
#

That's what auto saving is for

spiral axle
#

Still though i could. maybe move functions around to the auto load, or just putting both save n load in the same script. or fucking idk,
making the variables be applied on the buttons themselves..but im not sure

pastel nest
#

Even if you don't want to save it to their file right away, you can make a separate file for autodata/resetdata that stores everything, and then you can clear that file if something in game happens that would need to erase that data (like game overs and whatnot)

pastel nest
#

Opening a file every time your scene initializes could be rough

#

Especially cause there's no close()

spiral axle
pastel nest
#

Yes

spiral axle
#

alright then

#

lets see..

#

maybe i put the json var in..the autoload? So it can be referenced in all buttons..

#

this is from the tutorial btw-

#

the question really is just.
how to make sure all of these scripts and nodes/scenes are all properly interacting with one another ig..
moving save n load to same script is doable im just scared
as is..literally any alternative probably

grizzled grove
#

you shoud stop saying I am scared, you are typing text into a file, then hitting a button to compile it.

#

it's why you first set up version control though, so you can mess up the code and with a single press of a button you revert it back to the last working state

#

but most of all you should just start typing in your preferred code editor instead of typing here. If you are actualy stuck, or don't understand something this forum, or creating a new one is the perfect place to come. But first try what you want to try, if it doesn't work, say what you were trying to achieve, what you did, how you did and then people can give feedback

grizzled grove
# spiral axle maybe i put the json var in..the autoload? So it can be referenced in all button...

A good way to save all your data is with groups:

# Note: This can be called from anywhere inside the tree. This function is
# path independent.
# Go through everything in the persist category and ask them to return a
# dict of relevant variables.
func save_game():
    var save_file = FileAccess.open("user://savegame.save", FileAccess.WRITE)
    var save_nodes = get_tree().get_nodes_in_group("Persist")
    for node in save_nodes:
        # Check the node is an instanced scene so it can be instanced again during load.
        if node.scene_file_path.is_empty():
            print("persistent node '%s' is not an instanced scene, skipped" % node.name)
            continue

        # Check the node has a save function.
        if !node.has_method("save"):
            print("persistent node '%s' is missing a save() function, skipped" % node.name)
            continue

        # Call the node's save function.
        var node_data = node.call("save")

        # JSON provides a static method to serialized JSON string.
        var json_string = JSON.stringify(node_data)

        # Store the save dictionary as a new line in the save file.
        save_file.store_line(json_string)

```This example is straight from the docs I linked yesterday. Just add all the scenes that need to be saved to the group name of your choosing, then add a script, or add it to your already exsisting script a method called "save"
Here you fill in all the variables that need to be saved

Then for the loading you to the same thing but just revert the logic
grizzled grove
# spiral axle maybe i put the json var in..the autoload? So it can be referenced in all button...

I think what you are asking here is how to load the data? is that what you are stuck on ?
You just do, again just the example of the docs

var player : Player = get_tree().get_first_node_in_group("Player")
# Load the file line by line and process that dictionary to restore
    # the object it represents.
    var save_file = FileAccess.open("user://savegame.save", FileAccess.READ)
    while save_file.get_position() < save_file.get_length():
        var json_string = save_file.get_line()

        # Creates the helper class to interact with JSON.
        var json = JSON.new()

        # Check if there is any error while parsing the JSON string, skip in case of failure.
        var parse_result = json.parse(json_string)
        if not parse_result == OK:
            print("JSON Parse Error: ", json.get_error_message(), " in ", json_string, " at line ", json.get_error_line())
            continue

        # Get the data from the JSON object.
        var node_data = json.data
        player.global_pos = node_data["player_global_position"]
#

But that last line will fail, but that was explained in the first 15 minutes of that video you watched, so am sure you will fix it yourself

#

player.health = node_date["player_health"] will work though

spiral axle
#

but yeah I'll close this forum in a bit.

#

but i imagine It's probably better if i..
Make the save and load part of the same script.
and then use groups, or just the dictionary probably.

#

y'know what, fuck it we ball

tender summitBOT
spiral axle
#

FUCK

#

I FIGURED OUT THE ISSUE WITH THE SOUN