The following warnings occurred:
Warning [2] count(): Parameter must be an array or an object that implements Countable - Line: 906 - File: showthread.php PHP 7.2.24-0ubuntu0.18.04.17 (Linux)
File Line Function
/showthread.php 906 errorHandler->error



Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Turn on/off
eliasfrost Offline
Posting Freak

Posts: 1,769
Threads: 34
Joined: Mar 2007
Reputation: 39
#1
Turn on/off

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. Tongue 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!

[Image: indiedb_88x31.png]
(This post was last modified: 10-18-2011, 12:09 PM by eliasfrost.)
10-18-2011, 11:46 AM
Find


Messages In This Thread
Turn on/off - by eliasfrost - 10-18-2011, 11:46 AM
RE: Turn on/off - by Tanshaydar - 10-18-2011, 11:50 AM
RE: Turn on/off - by eliasfrost - 10-18-2011, 11:52 AM
RE: Turn on/off - by eliasfrost - 10-18-2011, 07:16 PM
RE: Turn on/off - by Your Computer - 10-18-2011, 07:31 PM
RE: Turn on/off - by eliasfrost - 10-18-2011, 07:35 PM



Users browsing this thread: 1 Guest(s)