# Best way to handle sound that is called between two integers?

Hello,

This may be a somewhat odd question, but I have been fiddling with how I handle music and sound in my game, and at the moment I am curious as to what the best way to handle it in the below situation would be.

Let’s say I have two intergers, 10 and 20.

Whilst the whatever variable is between these two, I want X song to play. Once it either falls below or rises above my set points, I want it to fade out and play a new song.

The code ive set up for this is the most basic version of that, with it doing a hard check at what that variable currently is and then fading in and out based on it.

However, the issue comes with saving. As right now my code only checks if it passes those two points, not whether it plays the sound based on where the variable is NOW.

I have thought about saving the variable to my gamemode, and maybe running a loop or something to check what it is, and then if the variable stays the same, continue the song and change nothing, but with this I wonder if it is the most effective way or there is another one better.

To summarize, what is the most effective way to handle sound calls between two integer points? Can I have a sound passively play forever whilst its between them, and switch to another when it is not?

I appreciate any ideas that might come along.

Can you place any code examples, because this description is big but however is not sharp enough in the sense of the problem you solve. For example, you have array of INT and array of USoundBase* which corresponds to each other. Is that right?

Sure thing, here is an example of how I have been handling my sound calls so far

As you can see, it is probably inefficient, hence why I have wondered if there is a better way.

https://puu.sh/GnuoI/66ec8ea38c.png

Well, I have several ideas:

1. Enums in fact do the same thing that you have - they just compare values, but this can be done with switch node. The problem is if uint8 is enough for you to list all the values

2. Use TMap and make your logic with iterating through this TMap. In body just put nodes to find the one item you want. It can be helpfull with simplifying the nodes

Havent seen a TMap before, ill do some research and check out what I can do. Thanks!

That helped me out, thanks very much friend!