2018-11-07 14:17:15

this topic will be for bgt questions i have, as they come up. So, first question!
How would I implement a pause menu in the middle of the round, and then when I hit p again, or click the resume game, it picks up where I left off? Would this require seeing the source?
also, How would I save the music volume, cause I want to be able to change it? I think I would use something like, if(KEY_PRESSED)(KEY_Pagedown)
{
music.volume-10
}

yo! so I'm working on programing, it's really hard. But I'll tell you where you can contact me if your stupid enough to do so.
Contact information:email: [email protected]
Skype: Brennan Draves
I'm usually found on online games, chatting, and being warned bye admins for talking to much, f**k you admin!

Thumbs up

2018-11-07 15:02:38

Pausing really depends on how your game is set up. The simplest way would be to make a pause function with a while loop that lasts until the player unpauses.
The way I'd rather do it is with a variable that tracks what part of the system the program is in—what screen it's on, if you'd prefer. In that case, I make an enum with all the different screens, and use a switch or if-else chain in the game's input and update functions to handle each. For pausing and unpausing, I'd also pause / resume sounds (if you're using the sound_pool, just use the pause_all and resume_all methods).
Either solution runs into  problems if you're using timers. I avoid this problem with a frame-clock, so you only need one while-loop, and know that every frame is the same length, excepting heavy lag.
As for saving the music volume, my solution is to either put it in a settings dictionary that gets saved/loaded on start / exit, or to use a settings menu(s) and save/load it via for-loop and string_to_number. The dictionary is probably easiest, since you don't have to worry about converting everything to and from text yourself, and can use the serialize and deserialize functions instead.

Some of my games
Keep up to date by following @Jeqofire on twitter!
Ear Ninja?

Thumbs up

2018-11-07 16:56:57

aaa, i'm not advanced enough to know what most of that ment, I sorta understood it, could you dumb it down a bit rofl?

yo! so I'm working on programing, it's really hard. But I'll tell you where you can contact me if your stupid enough to do so.
Contact information:email: [email protected]
Skype: Brennan Draves
I'm usually found on online games, chatting, and being warned bye admins for talking to much, f**k you admin!

Thumbs up

2018-11-09 20:24:15

I think you should learn the manual so you can understand the answers we give you. Do you even know how to use dictionaries or know what the string_to_number function does?

Ivan

2018-11-09 21:05:33

To be fair, BGT's dictionaries are kinda cumbersome. Python, Javascript, Java, all have much more intuitive implementations of the same concept. Bonus: Python stores just about everything in the current session in a dictionary, making it easy for something like Dill to save/load.
I almost always write a function or method to make retrieving dictionary entries simpler, in BGT. I think I uploaded a zip with quickdict.bgt, where it's reduced to a handful of get functions for primitives. And there's a global dictionary (just called a), so anything that needs to be serialized can be set easily from anywhere.

There's a serialization tutorial in the manual, but this example should work if you have quickdict:

#include "quickdict.bgt"

void save_settings() {
  string data = serialize (a);
  // I'd encrypt it, just to be safe:
  text = string_encrypt(text, "I don\'t remember if this is the right order.");
  file fout;
  fout.open ("data.dat", "wb");
  fout.write (text);
}
bool load_settings () {
  // Returns true on success, false on failure.
  if(!file_exists("data.dat") return false;
  file fin;
  fin.open ("data.dat", "rb");
  string text = fin.read();
  fin.close();
  text = string_decrypt (text, same_key_as_before); // What possessed me to use such a long key while typing on my phone?
  a = deserialize (text);
  return true;
}

void initialize () {
  if (load_settings()) return; // If we already have a file saved, just do that.
  else { // Set some defaults:
   a.set ("bgm volume", -10);
    // etc.
  }
}

void change_bgm_volume (float amount) {
  bgm.volume = bgm.volume + amount;
  // I'm making it more complicated, here, because I sometimes temporarily adjust volume for cut scenes, or let music fade in/out during gameplay, so we actually want to set these separately:
  float vol = getf ("bgm volume");
  vol += amount;
  if (vol>0) vol=0;
  else if (vol<-100) vol=-100;
  a.set ("bgm volume", vol);
}

// now we let the player change volume:
void system_keys () {
  if (key_pressed(KEY_PRIOR)) change_bgm_volume (5);
  else if (key_pressed (KEY_NEXT)) change_bgm_volume (-5);
}

Generally speaking, it would be better to teach than to give usable examples, but judging by where you are in the process, an example to take apart and put back together would probably be useful.
After all, I haven't tested the above, and the bit with the encryption key has a problem as written.

Some of my games
Keep up to date by following @Jeqofire on twitter!
Ear Ninja?

Thumbs up