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
Button (On) (Off)
User01 Offline
Member

Posts: 97
Threads: 30
Joined: Feb 2013
Reputation: 0
#1
Button (On) (Off)

Hi I can't make a simple on off function. I'm only aware how to make an event happen if you press one or several buttons. But idk how to make second event to happen if you press button again and loop it. Also, is there a way to variable it?

PHP Code: (Select All)
void button(string &in asEntity)
{
AddGlobalVarInt("button", +1);
}
else
{
AddGlobalVarInt("button", -1);

I tried this methode with +1 meaning ON and -1 is off. It didn't work at all.
03-06-2018, 07:09 PM
Find
Mudbill Offline
Muderator

Posts: 3,881
Threads: 59
Joined: Apr 2013
Reputation: 179
#2
RE: Button (On) (Off)

Your syntax is incorrect. You have the else statement, but you never asked the if statement, so it doesn't know what to do. How about this:

PHP Code: (Select All)
void button(string &in asEntity)
{
    if(
GetLocalVarInt("button") != 0// ON
    
{
        
SetLocalVarInt("button"0); // set to OFF
        // Do stuff
    
}
    else
    {
        
SetLocalVarInt("button"1); // set to ON
        // Do stuff
    
}


Here, value 0 (which is default) is treated as OFF and any other value is treated as ON. That should be safest. I'm also using the Set function rather than the Add function to be more restrictive about the possible states. This is only useful if you have only these 2 states the button can be in - using Add can be useful if you have many different states after each other.

03-07-2018, 02:46 AM
Find




Users browsing this thread: 1 Guest(s)