Frictional Games Forum (read-only)
Button (On) (Off) - Printable Version

+- Frictional Games Forum (read-only) (https://www.frictionalgames.com/forum)
+-- Forum: Amnesia: The Dark Descent (https://www.frictionalgames.com/forum/forum-6.html)
+--- Forum: Custom Stories, TCs & Mods - Development (https://www.frictionalgames.com/forum/forum-38.html)
+---- Forum: Development Support (https://www.frictionalgames.com/forum/forum-39.html)
+---- Thread: Button (On) (Off) (/thread-54315.html)



Button (On) (Off) - User01 - 03-06-2018

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:
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.


RE: Button (On) (Off) - Mudbill - 03-07-2018

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:
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.