LinkedAudio command and Volume Scaling (Similar to SetRoomLocation)

Started by Haffhedd, Mon 31/03/2014 18:45:00

Previous topic - Next topic

Haffhedd

Hey All,

Hope you're doing well. :-D

I have a few scripting questions, with the first being of the highest priority. Also it goes without saying that I am not a programmer so please be patient with me.



  • The first question relates to the LinkedAudio command in AGS 3.3

    First the explanation:

    What I'm hoping to do is assign a sound effect to a given View for footsteps. I'd like to have these sound effects operate similar to the SetRoomLocation command that exists for *AudioChannel functions.

    In other words, I'd like the footsteps to be full volume when the player is closer to the foreground and quieter when they are in the distance.

    How would I go about doing this?

    Here is my script for a single View Frame:

Code: ags

ViewFrame *frame1 = Game.GetViewFrame(EGOWLKDAY, 0, 3);
frame1.LinkedAudio = aFS_Wood1;



  • I'm obviously going to be working with a lot of View Loops for different perspectives.

    Let's say I wanted to assign the same sound effect above (Loop 0, Frame 3), to all loops for the character, which in this case is Loop 0 to 7.

    Is there an efficient way to code this, rather than copy pasting the code above and swapping the loop variables?



  • Expanding on this further, if I wanted to have the sound effects for Frame 3 of All Loops trigger another sound at random so it is not always the same sound playing (let's call this aFS_Wood2 and/or aFS_Wood3), how would I adjust the code?



  • And lastly, if everything above wasn't enough (what can I say? I'm a bum :P), is it possible to use other *AudioChannel functions with the LinkedAudio command, such as .Panning and .Volume? If not, any suggestions for how to incorporate these would be greatly appreciated.


If you have got this far and don't have the urge to facepalm or strangle me, congrats! Otherwise, I am deeply sorry.

Thanks in advance,
- Haff
-Haff

Haffhedd

Hey all,

No takers yet. Understandable.
I seem to have made some headway on my own. I'll try to explain what I've managed to do and the issues that remain.

My error was treating the LinkedAudio command like an equal to the *AudioChannel function. I realize now that it operates exclusively as an AudioClip and is limited by the same functionality (which answers my last question).

My workaround, correct or otherwise, was to create a custom Audio Type. I labelled this Type as Foosteps.

Conveniently the room I am working on has a Min and MaxScalingLevel set for the Walkable Area. These scaling values give me something to reference when determining a player's relative distance in game, setting the volume level as appropriate.

Using the command Game.SetAudioTypeVolume in conjunction with eVolExistingAndFuture + GetScalingAt, I'm able to create a 'stand in' for SetRoomLocation.

Understand that it's not quite as smooth, since the volume and locations are fixed into 3 separate zones.

My Code looks like this:

Code: ags

// Sets the Volume Scaling for the Footsteps Audio Type as it relates to Walkable Area Scaling

//Max Value
if (GetScalingAt(player.x, player.y) >= 90)
{
    Game.SetAudioTypeVolume(eAudioTypeFootsteps, 60, eVolExistingAndFuture);
}

//Min Value
else if (GetScalingAt(player.x, player.y) <= 57)
{
    Game.SetAudioTypeVolume(eAudioTypeFootsteps, 20, eVolExistingAndFuture);
}

//Median Value
else
{
    Game.SetAudioTypeVolume(eAudioTypeFootsteps, 40, eVolExistingAndFuture);
}


This approach 'works', but ideally I'd like a range.

Might want to read this next part slow. I can't figure out a way to make this information easy to digest.

So let's say I want 20% to be the Minimum Volume and 60% to be the Maximum Volume.
Rather than having the Footsteps volume at Max when the player is over 90% scaling, it should be within 50-60% Volume depending on how close they are to 100% scaling.
Then the Median would be from 40-49% Volume (when greater than 58% scaling, but less or equal to 89% scaling), and the Min from 20-39% Volume (Scaling is below 57%).

Any advice for how to do this would be appreciated.


The next major nitpick relates to my second point of the original post.

I tried to experiment with Operators to see if I could create an integer that accounts for all View Loops.

My code looked something like this (doesn't work at all, I clearly don't use Operators enough):

Declared variables.
Code: ags

int f, loop;

Then inside the function...
Code: ags

loop = (f >= 0 && f <= 7);

ViewFrame *frame1 = Game.GetViewFrame(EGOWLKDAY, loop, 3);
frame1.LinkedAudio = aFS_Wood1;


This does work for a single instance of View Loop 0, but it doesn't work for all instances. I believe it has something to do with the 'frame1' function.

I don't know if it's possible to create a 'frameX' function or if I should try a different approach all-together.

In the meantime, the 'bloated' method of scripting a sound per individual loop+frame does work. Saying that, I'm optimistic there's a better method to condense the code.

- Haff
-Haff

SMF spam blocked by CleanTalk