I apologize if this rookie question causes annoyance to people, but I've been thinking about it for days.
A few days ago I discovered a Python module called "wget", which I want to use to create an in-game asset downloader. It is a fairly simple module to use and works perfect for downloading files.
This is the code I use to make it work in the Python interpreter:
Code: Select all
## "wget" module for download files
import wget
## Links and file output
Assets_Link = "The URL of the files"
print("Acquiring URL...")
## This function shows download status (Percent and bytes)
## Example : Downloading... 10% [0 / 1024] Bytes
def status_custom(current, total, width=80):
print("Downloading... %d%% [%d / %d] Bytes" %(current / total * 100, current, total))
## MODULE IN ACTION [DOWNLOAD FILES]
try:
update_download = wget.download(Assets_Link, bar=status_custom)
update_received = True
except:
update_received = False
if update_received:
print("The game is Up-to-date! :D")
else:
print("Oops. Something went wrong :(")
I have adapted the code into a ".rpy" script which works perfect except for one thing. I can't show the download indicator on the interface.
The code adapted to the Ren'Py environment is this:
Code: Select all
init python:
import wget
## [UI] Download screen
screen Upd_Downloading():
vbox at prompt_anim_2:
text "Downloading..." style "Connecting_Data" xalign 0.5
null height 25
text "Getting game files..." style "Warning_Message_02" xalign 0.5
text "Path : [persistent.File_Name]" style "Warning_Message_02" xalign 0.5
text ## Show the download status here ##
## The game starts here
label start:
show screen Upd_Downloading
scene background_01 with dissolve
python:
Assets_Link = "The URL of the files"
## Function for show download status
def status_custom(current, total, width=80):
print("Downloading... %d%% [%d / %d] Bytes" %(current / total * 100, current, total))
try:
## The download starts here
update_download = wget.download(Assets_Link, bar=status_custom)
update_received = True
except:
update_received = False
## Dialogue blocks
if update_received:
"The game is Up-to-date! :D"
else:
"Oops. Something went wrong :(\nTry again!"
The idea is that this screen is able to show the current status of the download, at the moment that "wget" is doing its job.
MY TRIES:
I tried to make the function return the status of the download using Text() to create a DynamicDisplayable() and thus display it on the screen using add, but I had no success.
I tried stupidly to put inside the screen, a line with text and the name of the function. I was also unsuccessful.
If I put the status_customfunction in a init python block, or before the python block where the download takes place, I get an error of type ZeroDivisionError (The values it shows are divided by zero, so it throws an error).
Help me please :"(