So, the tweens are controlled by two independent buttons? If that’s the case, why not just set a variable in those button callbacks that tell you what you need to know?
I’m not exactly sure what you mean. Each tween created is meant to be controlled by a button, but each of the buttons is also made out of code based on other things. So I can’t just attach a script to set a variable based on the button being pressed. I am kind of new at this, so it’s possible I have just overlooked something important.
button is connected to some code via a signal (like
button_down). Those signals are, in turn, connected to a callback function that contains the code that runs when the signal is triggered (by interacting with the button).
I was suggesting that you could set a variable in the callback functions to track whatever you need.
If that’s now what you’re doing, maybe you could provide some more information.
jgodfrey | 2020-05-12 23:59
Oh, I see what you mean. Yes, the function that creates the tween and is supposed to use the tween to either fade in or fade out the audio is called by the button. The problem is that if I define the variable in the function, then it just gets overridden, unless I am just not doing something right?
Here is what I have tried:
At the top of the function _OnButtonPressed(): is
if FadingOut == true:
FadingOut = false
FadingOut = true
But this always returns false and prints “not” because FadingOut is not true when it is defined at the top of the function, right? And subsequently any attempts to create a simple toggling mechanism with this solution would break when the button is pressed as the variable is reset.
I have other buttons generated by other functions which use code like what I just posted above, but these buttons all edit the same global variable which is defined at ready and then used by all those buttons.
Seems like we’re still missing each other. As a baseline, I’m picturing something like the below (for example):
var fadingIn = false
fadingIn = true
# do fadeIn tween
fadingIn = false
# do fadeOut tween
Now, why won’t that work, or what are you doing differently? Also, with something like the above, I’m not even sure why you’d need the boolean variable…
jgodfrey | 2020-05-13 01:50
I can’t do exactly that because it’s the same button that I would like to have be essentially a toggle between fading in and fading out, and because the amount and name of the buttons and corresponding tweens is dependent on various different conditions of the app, I can’t define a variable for all of them at the top of the script. What I would need is to have the function create something like the code you posted, but uniquely, for each button that is generated. And that I have no idea how to do or a better solution to the problem.
I have found a solution. It may not be the most efficient, but it is simple enough. There is a an array which is created on read:
onready var ActiveTweens = 
This array is then called when the function needs to know whether the Tween node is going up or down. When the name of the Tween Node exists in the array, the function switches to fade in and deletes it from the array, and vice-versa much like the standard toggle function described above:
Use interpolate_property to fade in to desired volume
Use interpolate_property to fade out to -80.00 dB
This way, the variables are stored such that each button and tween can access their variables at any time (or the same time), but not in a way that would cause them to “cross streams” and interfere like they would with a single variable. It also will be somewhat useful to be able to print this array for debugging purposes later, now that I think of it. Thanks for the help, you set me on the right path it seems and I figured something out that works.