Create game data folder in AppData
To get the AppData path through Python and create your game data folder in it, simply use:
import os, pathlib
# Concatenate the APPDATA environment variable to the game folder name,
# then create a pathlib.Path object, allowing easier path manipulation
pathGameData = pathlib.Path(os.environ["APPDATA"] + "/My Game Folder")
# Creates game directory if not already exists
if not pathGameData.exists():
Downloading a file from URL
To download a file from a url:
from urllib.request import urlopen
# Download the file from URL
fileData = urlopen("https://github.com/bgempire/TedTheFrog/raw/master/Ted%20The%20Frog.blend")
# Read the downloaded data into memory as bytes
fileData = fileData.read()
The data will be downloaded into memory as bytes. You can use the downloaded blend file in two ways.
Saving to a file
To save downloaded data to a file, simply write it as bytes:
# The target file path to write downloaded data
resultingBlendFile = pathGameData / "DownloadedBlendFile.blend"
# Open the given file path in 'write bytes' mode
with open(resultingBlendFile.as_posix(), "wb") as openedFile:
After the file is saved, you can load it using
bge.logic.LibLoad functions as usual.
bge.logic.LibLoad accepts a bytes
data parameter, you can
LibLoad the data directly into the game:
# The parameters are: libName, whatToLoad, bytesData
bge.logic.LibLoad("DownloadedLib", "Scene", fileData)
I don’t have idea what you mean.