{"name":"set","operator":null,"title":"set","type":"command","url":"https://community.bistudio.com/wiki/set","revid":377132,"updated":"2026-01-01T10:26:06Z","groups":["Arrays","HashMap"],"status":"ok","replaced_by":[],"games":[{"game":"ofp","name":"Operation Flashpoint","version":"1.75"},{"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.75"},"arma3_since":"0.50","branch":null,"locality":{"argument":null,"effect":null,"server_exec":false},"exec":null,"description":"Changes the element at the given zero-based index of the array.\n\n> [!NOTE]\n> If the index is out of bounds, the array will resize to incorporate the index as its last value, padding with nil as necessary (see #Example 4).","syntaxes":[{"syntax":"array set [index, value]","since":null,"effect":null,"exec":null,"params":[{"name":"array","type":"Array of Anything","optional":false,"default":null,"description":null,"types":["Array","Anything"],"since":null,"text":"array: Array of Anything"},{"name":"index","type":"Number","optional":false,"default":null,"description":"0-based array index. Arma 3 v2.12 negative index can be used to select from the end of the array, i.e. -1 means last array element.","types":["Number"],"since":null,"text":"index: Number - 0-based array index. Arma 3 v2.12 negative index can be used to select from the end of the array, i.e. -1 means last array element."},{"name":"value","type":"Anything","optional":false,"default":null,"description":null,"types":["Anything"],"since":null,"text":"value: Anything"}],"returns":{"type":"Nothing","types":["Nothing"],"description":null,"text":"Nothing"},"form":"binary","operator":null,"left":{"text":"array","types":["Array","Anything"]},"right":{"text":"[index, value]","types":["Array"]}},{"syntax":"hashMap set [key, value, insertOnly]","since":"arma3 2.02","effect":null,"exec":null,"params":[{"name":"hashMap","type":"HashMap","optional":false,"default":null,"description":null,"types":["HashMap"],"since":null,"text":"hashMap: HashMap"},{"name":"key","type":"HashMapKey","optional":false,"default":null,"description":null,"types":["HashMapKey"],"since":null,"text":"key: HashMapKey"},{"name":"value","type":"Anything","optional":false,"default":null,"description":null,"types":["Anything"],"since":null,"text":"value: Anything"},{"name":"insertOnly","type":"Boolean","optional":true,"default":"false","description":"if set to true, set the value only if the key does not exist already","types":["Boolean"],"since":"arma3 2.08","text":"insertOnly: Boolean - (Optional, default false) if set to true, set the value only if the key does not exist already"}],"returns":{"type":"Boolean","types":["Boolean"],"description":"false if the key is new to the hashmap, true if a value got overwritten","text":"Boolean - false if the key is new to the hashmap, true if a value got overwritten"},"form":"binary","operator":null,"left":{"text":"hashMap","types":["HashMap"]},"right":{"text":"[key, value, insertOnly]","types":["Array"]}}],"examples":[{"text":"```sqf\n_arrayOne set [0, \"Hello\"];\n```","code":["_arrayOne set [0, \"Hello\"];"]},{"text":"Append \"Bye\" as last element to `_arrayTwo`:\n\n```sqf\n_arrayTwo set [count _arrayTwo, \"Bye\"];\n```","code":["_arrayTwo set [count _arrayTwo, \"Bye\"];"]},{"text":"Replace the last element of `_arrayThree` with 23:\n\n```sqf\n_arrayThree set [(count _arrayThree) - 1, 23];\n```","code":["_arrayThree set [(count _arrayThree) - 1, 23];"]},{"text":"Using set with an index that is out of bounds:\n\n```sqf\nprivate _array = [\"A\"];\n_array set [2, \"C\"]; // _array is now [\"A\", nil, \"C\"]\n_array set [1, \"B\"]; // _array is now [\"A\", \"B\", \"C\"]\n```","code":["private _array = [\"A\"];\n_array set [2, \"C\"]; // _array is now [\"A\", nil, \"C\"]\n_array set [1, \"B\"]; // _array is now [\"A\", \"B\", \"C\"]"]},{"text":"```sqf\nprivate _myHashMap = createHashMap;\n_myHashMap set [\"key\", \"value1\", true]; // \"key\" value is set to \"value1\"\n_myHashMap set [\"key\", \"value2\", true]; // \"key\" value is still \"value1\" as \"key\" already exists in the hashmap\n```","code":["private _myHashMap = createHashMap;\n_myHashMap set [\"key\", \"value1\", true]; // \"key\" value is set to \"value1\"\n_myHashMap set [\"key\", \"value2\", true]; // \"key\" value is still \"value1\" as \"key\" already exists in the hashmap"]}],"multiplayer":null,"problems":null,"aliases":[],"see_also":["resize","reverse","select","deleteAt","deleteRange"],"notes":[],"categories":["ArmA: Armed Assault: Scripting Commands","Arma 2: Operation Arrowhead: Scripting Commands","Arma 2: Scripting Commands","Arma 3: Scripting Commands","Command Group: Arrays","Command Group: HashMap","Introduced with Operation Flashpoint version 1.75","Operation Flashpoint: Elite: Scripting Commands","Operation Flashpoint: New Scripting Commands","Operation Flashpoint: Scripting Commands","Scripting Commands","Take On Helicopters: Scripting Commands"]}