If statement for audio - talking over one another


#1

Hello,

I’m working with 3D animation files and audio files (ogg). I’ve managed to get the animation files to start and stop, but audio files only let me play and pause (why is there a difference?).

I think I need to create an if statement for the following, but I’m not sure where to start, or if it’s the correct way to do it:

My Menus and Buttons work in a similar way:
I have Menu 1 with Button 1.1, Button 1.2, Button 1.3, and Button 1.4.
I have Menu 2 with Button 2.1, Button 2.2, Button 2.3, and Button 2.4.
etc
Click Button 1 to get to Menu 2 > this will close Menu 1, will open Menu 2, and will play an audio file.

This all works.

The problem is that sometimes the audio files talk over one another if I’ve pressed another button. I need to write a script that only allows one audio file to be played at one time. They can be interrupted, but then the audio file needs to stop and the next one begin. I also need the audio file to stop - not just pause - because it will need to start from the beginning again, so I guess I’ll need to use both pause and restart at some point?

Something like:

If Audio 1 is playing, all other audio files are not playing / disabled and all other buttons are disabled

I don’t want to use timelines or a videoplayer symbol for this, so I’m putting the audio files in the hierarchy and then calling them through script using:

symbol.nodes.voiceover_section_4_ogg.start();
or
symbol.nodes.voiceover_section_4_ogg.pause();

Any advice on how to get started is very welcomed!

Thanks very much in advance, Forum!


#2

There is also a restart(); to restart the audio file.
Here is a zpp file I made to help someone.
Audio Help.zpp (1.4 MB)

It’s not 100% what your looking for but should help get you going.

Steve


#3

@stevesanerd: You are too kind! :trophy: I was just hoping for some guidance code, but you went to the next level!

I will take a look and report back - thanks very much.


#4

Your very welcome. Let me know if you need anything else.

Steve


#5

Hey again @stevesanerd!

Just to say that your code was very helpful for what I’m working on, and some of it I had actually already written, so it’s good to know I was on the same path! Yours is definitely more concise than mine, though, so that helped me learn more on the coding and logic side of things.

Imagine, I have 8 menus, each with 4 buttons and when I press a button, it closes the current menu and opens a new one: I’m using this script and copying and pasting it on every single button, but I’ve making a few amendments here and there to personalise it for each one: is there a more elegant way of doing this, like referencing a master script and not having to copy and paste and repeat so much? I’m still learning the ways of logic.


#6

So I hope this doesn’t throw you to much.
For what you are looking for a Sub symbol works best. I made a sub symbol called menu button with 4 sub buttons in it. You can press the main button to open and close it. When you press the buttons I have it emitting open,closed and sub1,2,3,4.

Next I placed 3 of the sub symbol menu button in the main symbol. I added code to close any open menu when one was pressed. There is code to help you with when the Sub Buttons are pressed as well.

Last you can change the text of each button under the References in Properties for each sub symbol you add. If you add more sub symbols You will just have to add to the coding to close the open menus and what to do when the sub buttons are pressed.

Steve
Menu Help.zpp (192.5 KB)


#7

Thanks as always, Steve! This was a bit complicated for me for this project, but I’ll try and use it in another. Thanks for your time again.