So I made a radio and I want to make it so that when you press it, you turn it on and when you press it again, it'll turn off. But I'm not sure how this is gonna work. I have the idea that I have to use boolean values as flags for wether it's on or off but that's pretty much as far as I've gotten. I can turn it on, but I can't turn it off. I have two code samples, the first one is only for turning it on to work, and the second one is an attempt to create another interaction function to turn it off once it's on, but it failed miserably.
First code piece:
void OnStart()
{
SetLocalVarInt("radio", 0);
SetEntityPlayerInteractCallback("Radio_1", "func1", true);
}
void func1(string &in asEntity)
{
if(GetLocalVarInt("radio") == 0)
{
PlayMusic("42_mono.ogg", true, 1, 2, 1, true);
SetLocalVarInt("radio", 1);
}
}
And here's the second code:
void OnStart()
{
SetLocalVarInt("radio", 0);
SetEntityPlayerInteractCallback("Radio_1", "func1", true);
}
void func1(string &in asEntity)
{
if(GetLocalVarInt("radio") == 0)
{
PlayMusic("42_mono.ogg", true, 1, 2, 1, true);
SetLocalVarInt("radio", 1);
}
if(GetLocalVarInt("radio") == 1)
{
StopMusic(2, 1);
SetLocalVarInt("radio", 0);
}
}
I have a feeling that since the "radio" var is loaded to 0 at the start of the code, it will trigger the first if statement and turn the variable to 1 and then it directly moves down to the next if statement and trigger it, again changing the variable back to 0. I wonder if there is a way to cancel the reading process in the middle of a function? So that I can end the function after each if statement. This is just what I think, please tell me if I'm far off.
Thanks
EDIT: Whoops! I accidentally put this in the wrong board, would a moderator be so kindly as to move it to the CS section? Thanks!