2014-07-01 16:34:43

*I wasn't sure where to post this but thought it would be OK here, although correct me if I'm wrong.*
Now that BGT is completely freeware, I thought I'd take a look at packing all my files into the *.dat files that bgt can encrypt etc.  However, I am very much confused as to where to begin, since that part of the tutorial as well as a few others are not particularly newbie friendly in terms of the examples...  Could anyone possibly provide me with an example of how to get all the sounds and things into a pack file that I could distribute along with my executable file?  or even better, the tutorial says that you can pack all your files into the exe.  Does that actually mean that you can have all your sounds and everything just packed into the executable itself and that's it  If so, as an extension of my earlier question, how would you go about doing this?

Any help is much appreciated.

My TARDIS: time and relative dimension in space machine.  its bigger. on the inside.  infinitely bigger on the inside.

2014-07-01 20:17:17

(My trackpad mysteriously came on and started clicking things and it ate my last attempt to reply. sad )


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. sad

看過來!
"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.

2014-07-02 21:59:49

Thanks very much for this script.  Actually, How would you pack 2 sicrectories - say "sounds" and "music" both in the root folder, into the pack file?  Also about the calls to the pack file(when used with the executable), when it says something like these calls should be used in wherever you would've refered to the pack file... I'm confused with this...

Additionally, if your script were to be used would you want credit for them?

Thanks again for your help.

a slightly OT note, where do you have your website hosted?  and how much does it cost you?

My TARDIS: time and relative dimension in space machine.  its bigger. on the inside.  infinitely bigger on the inside.

2014-07-03 15:54:03

Thanks, thanks, thanks, thanks. I was looking to know that from a long time.

2014-07-03 15:59:21

Of course, I'll give you the credit everyware I use this scrypt, you're a legend: I can, after reviewing slowly the scrypt, understand how it works.

2014-07-04 10:53:07

Hi Cae. Thanks, it worked with me, but how can we let something play looped in the test?

2014-07-04 10:59:04 (edited by Riad 2014-07-04 10:59:49)

And also, how can we make the sound pann in the .dat, and how can we change its pitch? I ask that because we're developping the boat simulator, me and Nathan Smith, so we'll protect the sounds with the .dat.

2014-07-04 14:00:09

And also, how to do the following:
for example:
if(key_pressed(KEY_Q))
a sound from the pack plays.

2014-07-04 17:41:44

At The Doctor: I have my website through Freeservers. In spite of their name, they cost about $100/year.

At Roro: You'd do it the same as with any other sound. For example:
if(key_pressed(KEY_Q)) {
pool.play_1d("sounds/mysound.wav", player_x, sound_x, true);
}

I think it works with regular sound objects as well. I use the sound_pool so much I'm not really sure, but I think that's the point of the set_sound_storage function.

看過來!
"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.

2014-07-04 20:00:29

Oh thanks very much for your help, I appreciate it.

2014-07-04 20:14:02 (edited by Riad 2014-07-04 20:33:04)

But what's wrong with this example scrypt?
#include "sounds.dat"
#include "sound_pool.bgt"
void main() {
show_game_window("the nay");
set_sound_storage("*");
if(key_pressed(KEY_G)) {
game();
}
void game();
ack_file test;
test.open("*");
while(true) {
sound_pool pool;
if(key_pressed(KEY_Q)) {
pool.play_1d("sounds/a.ogg", player_x, sound_x, true);
wait(50));
test.close();
}
}
This is a small part I wrote very fastly, so it contains an error. But what it is?

2014-07-04 21:05:55

There are three errors I found on a quick reading:
1. You have "ack_file test;" instead of "pack_file test;"
2. The sound_pool is declared inside the loop, so there's a good chance it won't play any sounds because it is destroyed and recreated each frame!
3. test.close() is inside the loop, but it should be outside.

看過來!
"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.

2014-07-04 22:05:54 (edited by Riad 2014-07-04 22:15:56)

Thanks, I wrote it quickly so I may be have some errors like that. You'll be always in my credits list.
Edit: Hi, I'm so sad I can't do it right, I'm always wrong, here's what I did:
#include "sounds.dat"
#include "sound_pool.bgt"
void main() {
show_game_window("the nay");
set_sound_storage("*");
sound_pool pool;
if(key_pressed(KEY_G)) {
game();
}
void game();
pack_file test;
test.open("*");
while(true) {
if(key_pressed(KEY_Q)) {
pool.play_1d("sounds/a.ogg", player_x, sound_x, true);
}
test.close();
}
}
I'll try to improve it, but I didn't found any errors myself here. Sorry, it's the first time I use sound encryption, so I'm sorry for that.

2014-07-05 13:35:07

you shouldn't have to declare a pack file object like you did because you already set the sound storage to the compiled executable. Also, you declare the sound pool in void main, then try an access it from the game function. eclare the pool as global.

I like to sleep, Sleep is good,
This is how I do it: Lie on a nice warm cozy bed, and dream dreams about how to rule the world!
Follow @TheGreatAthlon5 on twitter for humorous facts and game updates!
If you like my posts, thumb me up!

2014-07-05 14:54:59

It still gives me a compiler error, and it's now like that:
#include "sounds.dat"
#include "sound_pool.bgt"
set_sound_storage("*");
sound_pool pool;
void main() {
show_game_window("the nay");
while(true) {
if(key_pressed(KEY_Q)) {
pool.play_1d("sounds/a.ogg", player_x, sound_x, true);
}
}
}

2014-07-15 15:08:21

Thanks for bringing this topic up. I was wondering how to do some of the things brought up in this topic. I'm thinking about trying pack files with the project maze thing I was working on a while back. I kind of like have all of my sounds being inside the EXE. LOL. Now to go and throw the sounds into a pack.

All that is gold does not glitter, Not all those who wander are lost; The old that is strong does not wither, Deep roots are not reached by the frost. From the ashes a fire shall be woken, A light from the shadows shall spring; Renewed shall be blade that was broken, The crownless again shall be king.
DropBox Referral