Frictional Games Forum (read-only)
What does "+=" do? - 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: What does "+=" do? (/thread-20493.html)



What does "+=" do? - tonitoni1998 - 02-25-2013

i saw it in the code lock script
( http://www.frictionalgames.com/forum/showthread.php?tid=20464&pid=203188&mode=threaded ) from NaxEla

i couldnt find it anywhere else.

Code:
void PressedButton(string &in entity)
{
    int buttonsPressed;
    
    AddLocalVarInt("ButtonsPressed", 1);
    
    playersGuessedCode += GetButtonPressed(entity);    /// HERE
    buttonsPressed = GetLocalVarInt("ButtonsPressed");
    
    AddDebugMessage("Buttons Pressed: "+buttonsPressed+"  Guessed Code: "+playersGuessedCode, false);
    
    if(playersGuessedCode == correctCode) {
        SetSwingDoorLocked("door", false, false);
        for(int i=0; i<=9; i++) {
            SetEntityActive("Button_"+i, true);
        }
        ResetCode();
        AddDebugMessage("Correct code!", false);
        
        return;
    }
    
    if(buttonsPressed == 4) {
        ResetCode();
        AddDebugMessage("Wrong code!", false);
    }
}



RE: What does "+=" do? - darksky - 02-25-2013

i += 1 is the same as i = i+1;


RE: What does "+=" do? - tonitoni1998 - 02-25-2013

so it actually just says "add"?


RE: What does "+=" do? - darksky - 02-25-2013

yes, i += x "add x to i, and store in variable i"

but you can also do -=, *=, /=


RE: What does "+=" do? - No Author - 02-26-2013

Got to refresh my brain for an hour after reading this.