Re: trying to solidify my understanding of coding concepts, and failing

Yes, this example is a good way to apply the concepts you learned about
handles. I'll make a example, let me know if you understood it, or if you became confused so I can explain it another way.

In this example, we'll create a function to play a random footstep. Why we'll use handles? Because if we use normal variables, each time we reference the footstep on the function, BGT will make a copy of the sound we referenced. And with a handle, you can prevent this copy and work with the original variable.

On the top of your script, you'd create a variable for each footstep:
sound step_1, step_2, step_3;

In your main function, you'll load each step sound separately, and in your move function, you could do something like this:
class player {
void move()
    {
    sound @step_sound;
    int r;

    // Generate a random number to select which step you want to play
    r = random(1, 3);

    if (r == 1)
        @step_sound = @step_1;
    else if (r == 2)
        @step_sound = step_2;
    else
        @step_sound = @step_3;

    step_sound.play(); // Equivalent to step_1.play() or the others, since the andle is a reference to the step chosen
}

Hope it helps a bit.

-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
  • ... AudioGames . net Forum — Developers room : musicalman via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : musicalman via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : thggamer via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : thggamer via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : chrisnorman7 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : ogomez92 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : bhanuponguru via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : musicalman via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : musicalman via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : thggamer via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : camlorn via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : musicalman via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : chrisnorman7 via Audiogames-reflector

Reply via email to