{"name":"switchLight","operator":null,"title":"switchLight","type":"command","url":"https://community.bistudio.com/wiki/switchLight","revid":364994,"updated":"2024-07-04T19:58:05Z","groups":["Lights"],"status":"ok","replaced_by":[],"games":[{"game":"ofp","name":"Operation Flashpoint","version":"1.00"},{"game":"ofpe","name":"Operation Flashpoint: Elite","version":"1.00"},{"game":"arma1","name":"Armed Assault","version":"1.00"},{"game":"arma2","name":"Arma 2","version":"1.00"},{"game":"arma2oa","name":"Arma 2: Operation Arrowhead","version":"1.50"},{"game":"tkoh","name":"Take On Helicopters","version":"1.00"},{"game":"arma3","name":"Arma 3","version":"0.50"}],"since":{"game":"ofp","name":"Operation Flashpoint","version":"1.00"},"arma3_since":"0.50","branch":null,"locality":{"argument":null,"effect":"local","server_exec":false},"exec":null,"description":"Controls whether a lamp is lit or not.\n\n> [!NOTE]\n> This command was originally designed to only work with `CfgNonAIVehicles` class `\"StreetLamp\"` only.\n> Since Arma 3 v1.92 this command was extended to work with street lights and some prop lights, like portable construction light.","syntaxes":[{"syntax":"lamp switchLight mode","since":null,"effect":null,"exec":null,"params":[{"name":"lamp","type":"Object","optional":false,"default":null,"description":null,"types":["Object"],"since":null,"text":"lamp: Object"},{"name":"mode","type":"String","optional":false,"default":null,"description":"mode can be: \"ON\", \"OFF\" or \"AUTO\" (*lamp* is on only during nighttime, default)","types":["String"],"since":null,"text":"mode: String - mode can be: \"ON\", \"OFF\" or \"AUTO\" (*lamp* is on only during nighttime, default)"}],"returns":{"type":"Nothing","types":["Nothing"],"description":null,"text":"Nothing"},"form":"binary","operator":null,"left":{"text":"lamp","types":["Object"]},"right":{"text":"mode","types":["String"]}}],"examples":[{"text":"```sqf\n(object 12345) switchLight \"OFF\";\n```","code":["(object 12345) switchLight \"OFF\";"]},{"text":"```sqf\nnearestObject [player, \"Streetlamp\"] switchLight \"OFF\";\n```","code":["nearestObject [player, \"Streetlamp\"] switchLight \"OFF\";"]},{"text":"```sqf\ncursorObject switchLight \"ON\";\n```","code":["cursorObject switchLight \"ON\";"]}],"multiplayer":null,"problems":null,"aliases":[],"see_also":["lightIsOn","BIS_fnc_switchLamp"],"notes":[{"user":"Killzone_Kid","date":"2013-09-16T11:14:00Z","text":"*Before Arma 3 v1.92* use setHit instead:\n\n```sqf\n_lamp = nearestObject [player, \"Lamps_base_F\"];\n_lamp setHit [\"light_1_hitpoint\", 0.97];    // off\n_lamp setHit [\"light_1_hitpoint\", 0];        // on\n```\n\nSwitch all lights off in the 500 radius of player:\n\n```sqf\nprivate _lamps = nearestObjects [player, [\"Lamps_base_F\", \"PowerLines_base_F\", \"PowerLines_Small_base_F\"], 500];\n\n{\n    for \"_i\" from 0 to (count getAllHitPointsDamage _x -1) do\n    {\n        _x setHitIndex [_i, 0.97];\n    };\n} forEach _lamps;\n```"},{"user":"Sa-Matra","date":"2023-03-01T14:12:31Z","text":"How to disable all lamps using the latest Arma 3 commands, a modern method. Disable all lights that are pre-placed on the map, on the entire map:\n\n```sqf\n{\n    _x switchLight \"OFF\";\n} forEach (1 allObjects 0);\n```\n\nDisable all script-spawned and editor-placed lamps:\n\n```sqf\n{\n    _x switchLight \"OFF\";\n} forEach (8 allObjects 0);\n```\n\nThese snippets iterate through all buildings and run switchLight on them. If they're lamps, they'll be turned off."}],"categories":["ArmA: Armed Assault: Scripting Commands","Arma 2: Operation Arrowhead: Scripting Commands","Arma 2: Scripting Commands","Arma 3: Scripting Commands","Command Group: Lights","Introduced with Operation Flashpoint version 1.00","Operation Flashpoint: Elite: Scripting Commands","Operation Flashpoint: New Scripting Commands","Operation Flashpoint: Scripting Commands","Scripting Commands","Scripting Commands: Local Effect","Take On Helicopters: Scripting Commands"]}