When to use variables versus files

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By DONOTJUDGEMYCODE


I’ve noticed that in the game Minecraft, there are many .json files inside that each specify a single thing (e.g. there is a file for every advancement). Now, I know Java and GDScript are both very different things, but I am still puzzled by one question that I feel still stands in GDScript.

Why not just make variables for each of these, instead of files, inside a script?

Basically, what I am asking is if it is a good idea to use this practice in Godot.


:bust_in_silhouette: Reply From: Ertain

Files are used for storing the program’s state, as well as bits of data. A program may have to read from a file, or write to it, to store information for later. A program will store values and variables in RAM (or similar media) when it runs. While a program can use files for storing data and its state when it’s running (some Unix-like OSes do that for certain processes), this may slow down the process, as the program is using some storage medium (e.g. a hard drive or an SSD). Usually, the storage medium is slower than using RAM. As such, the program will use a file when storing something for later. When the program needs to keep data available (and quickly access the data), it will use RAM.

Hope that answers your question.