(My trackpad mysteriously came on and started clicking things and it ate my last attempt to reply. )
I don't know if I can do anything better than the tutorial, but I'll try a simple example.
... assume any minor errors are a test. ... Yeah.
// Pack all files in a certain directory, recursive.
// This probably needs to be in its own script; pack everything separately from the game, otherwise it will do weird things when someone tries to play it.
// Both parameters here have a default value, so you can just call pack_all().close() and that's everything. You might try pack_all("sounds") if you only want the sounds folder, for example.
pack_file@ pack_all(string top="", pack_file@ ret=null) {
if(@ret==null) {
pack_file temp;
@ret=temp;
ret.create("data.dat");
}
// Formatting:
if((top!="")&&(string_right(top, 1)!="/")&&(string_right(top, 1)!="\\")) {
top += "/";
}
string[] dirs=find_directories(top + "*");
string[] files=find_files(top + "*");
for(uint i=0; i<files.length(); i++) {
ret.add_file(top + files[i], top + files[i]); // The filename in the pack matches the filename on the system.
}
for(uint i=0; i<dirs.length(); i++) {
pack_all(top + dirs[i], ret); // Since ret is a handle, we shouldn't need to save it, but if this doesn't work, try adding @ret= to the start of this line.
}
return ret;
}
void main() {
// Example, packing everything in ./sounds
pack_all("sounds/").close();
}
// Now, a program that plays a file froun the sounds pack, while including it in the executable:
#include "data.dat"
#include "sound_pool.bgt"
void main() {
set_sound_storage("*"); // Now, whenever we try to load a sound, it will look in data.dat. The * indicates that it's the included pack.
pack_file test;
test.open("*"); // You can now access files from the icnluded pack directly, if you need to.
sound_pool pool;
pool.play_stationary("sounds/sound001.wav", false);
wait(1000);
test.close();
alert("Done", "You should have heard an included sound.");
}
}
I have no idea if this was helpful.
看過來!
"If you want utopia but reality gives you Lovecraft, you don't give up, you carve your utopia out of the corpses of dead gods."
MaxAngor wrote:
George... Don't do that.