Page 1 of 1
Downloadables
Posted: Mon Jan 07, 2013 10:55 am
by satoon101
I have only done minor tests on the new Python-side Downloadables, but my tests so far seem to work just fine (with the newest updated code). You should use it something like the following:
Syntax: Select all
from core.downloads import Downloadables
# Get an instance of Downloadables
downloads = Downloadables()
# Add files you want using the path from the game's path
downloads.add('materials/models/test.vmt')
downloads.add('materials/models/test.vtf')
downloads.add('sound/source-python/test.mp3')
Unloading the script will remove the items from the Python-side list, but will not remove them from the actual stringtable for downloadables. Changing the map should do the trick for that.
Satoon
Posted: Mon Jan 07, 2013 11:08 am
by L'In20Cible
Very nice!

Posted: Mon Jan 07, 2013 4:55 pm
by Woody
Thanks! Nice work!

Posted: Mon Dec 01, 2014 8:47 pm
by 8guawong
how do you add a list of file to the Downloadables??
Syntax: Select all
from stringtables.downloads import Downloadables
import os.path
from path import Path
dl = Downloadables()
base_path = Path(__file__).parent
with open(base_path + '/models.txt', 'r') as open_model_file:
for line in open_model_file:
stripped_line = line.rstrip()
d1.add("%s" % stripped_line)
Code: Select all
[SP] Caught an Exception:
Traceback (most recent call last):
File '../addons/source-python/packages/source-python/plugins/manager.py', line 72, in __missing__
instance = self.instance(plugin_name, self.base_import)
File '../addons/source-python/packages/source-python/plugins/instance.py', line 82, in __init__
self._plugin = import_module(import_name)
File '../addons/source-python/plugins/download/download.py', line 10, in <module>
d1.add('%s' % stripped_line)
NameError: name 'd1' is not defined
Posted: Mon Dec 01, 2014 8:58 pm
by satoon101
Did you really look at the error you just posted? It clearly states what your issue is.
Also, there is no need to use "%s" % stripped_line , just use stripped_line
Posted: Mon Dec 01, 2014 9:00 pm
by Ayuto
The problem is that you defined
dl, but you are trying to access the variable
d1 which doesn't exist.
Syntax: Select all
from stringtables.downloads import Downloadables
from path import Path
dl = Downloadables()
base_path = Path(__file__).parent
with open(base_path / 'models.txt', 'r') as open_model_file:
for line in open_model_file:
stripped_line = line.rstrip()
dl.add(stripped_line)
Edit: Satoon was faster :(
Posted: Mon Dec 01, 2014 10:10 pm
by 8guawong
lol sorry tired as hell
didn't notice d1 and dl

Posted: Mon Dec 01, 2014 10:23 pm
by 8guawong
so there is no need of the ' ' mark??
if i just want to download 1 file
Syntax: Select all
downloads.add(materials/models/test.vmt)
is ok as well???
vs.
Syntax: Select all
downloads.add('materials/models/test.vmt')
i
Posted: Mon Dec 01, 2014 10:32 pm
by L'In20Cible
You need to pass a string so the quotes are needed. In your first example, you are trying to add the result of a math operation with variables that doesn't exists in your code.
Posted: Mon Dec 01, 2014 10:33 pm
by satoon101
You must pass a string. When you are reading the lines of a file, you are already reading string values. If you were to use print(type(stripped_line).__name__) , it would show str . Since materials/models/test.vmt is not a 'variable', you have to make it a string by using quotes or apostrophes.
*Edit: L'In20Cible beat me
Posted: Mon Dec 01, 2014 10:36 pm
by Doldol
No not at all, you want to specify text, which you do in Python by using strings, which need " or ' around them.
Simply put look at the highlighting, if it's green on this website, it's seen as text by Python.
Posted: Mon Dec 01, 2014 10:39 pm
by 8guawong
ah ok thanks now i get it
