{"name":"assert","title":"assert","type":"command","url":"https://community.bistudio.com/wiki/assert","revid":363603,"updated":"2024-04-08T09:49:06Z","groups":["Program Flow"],"status":"ok","games":{"arma1":"1.00","arma2":"1.00","arma2oa":"1.50","tkoh":"1.00","arma3":"0.50"},"since":"arma1 1.00","arma3_since":"0.50","description":"Tests a condition and if the condition is false, displays error on screen (if -showscripterrors enabled) and logs error into .rpt file. It does not interrupt the script execution.\n\nIf script was pre-processed with preprocessFileLineNumbers, it will also show/log the error line number and the file name.","syntaxes":[{"syntax":"assert condition","params":[{"name":"condition","type":"Boolean","type_expr":"Boolean"}],"returns":{"type":"Boolean","type_expr":"Boolean","description":"mirrors condition"},"form":"unary","right":{"text":"condition"}}],"examples":[{"code":["assert (1 > 2);"]},{"text":"Check function params (Faster alternative to BIS_fnc_param)\n\n```sqf\nsome_func = {\n    _0 = _this select 0;\n    _1 = _this select 1;\n    _2 = _this select 2;\n    if (!assert (\n        typeName _0 == \"ARRAY\" &&\n        typeName _1 == \"STRING\" &&\n        typeName _2 == \"SCALAR\"\n    )) exitWith { /* optional error logging */ };\n    hint \"Alright!\";\n};\n[1,2,3] call some_func; // assert error\n[[1],\"2\",3] call some_func; // Alright!\n```","code":["some_func = {\n\t_0 = _this select 0;\n\t_1 = _this select 1;\n\t_2 = _this select 2;\n\tif (!assert (\n\t\ttypeName _0 == \"ARRAY\" && \n\t\ttypeName _1 == \"STRING\" &&\n\t\ttypeName _2 == \"SCALAR\"\n\t)) exitWith { /* optional error logging */ };\n\thint \"Alright!\";\n};\n[1,2,3] call some_func; // assert error\n[[1],\"2\",3] call some_func; // Alright!"]}],"see_also":["try","catch","throw","halt","diag_captureFrame","diag_captureSlowFrame","diag logSlowFrame"],"notes":[{"user":"RoehrenRadio","date":"2010-05-15T00:01:00Z","text":"Returns false, if condition is false, and returns true, if condition is true."}]}