assert: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Text replacement - "<code>([^<]*)<nowiki\/?>([^<]*)<\/code>" to "<code>$1$2</code>")
m (Some wiki formatting)
Line 32: Line 32:
[[Image:PreprocessFile.jpg]]
[[Image:PreprocessFile.jpg]]


|x2= Check function params (Faster alternative to [[BIS_fnc_param]])<code>some_func = {
|x2= Check function params (Faster alternative to [[BIS_fnc_param]])
_0 = _this [[select]] 0;
<sqf>
_1 = _this [[select]] 1;
some_func = {
_2 = _this [[select]] 2;
_0 = _this select 0;
if (![[assert]] (
_1 = _this select 1;
[[typeName]] _0 == "ARRAY" &&  
_2 = _this select 2;
[[typeName]] _1 == "STRING" &&  
if (!assert (
[[typeName]] _2 == "SCALAR"
typeName _0 == "ARRAY" &&  
)) [[exitWith]] { {{codecomment|/* optional error logging */}} };
typeName _1 == "STRING" &&
[[hint]] "Alright!";
typeName _2 == "SCALAR"
)) exitWith { /* optional error logging */ };
hint "Alright!";
};
};
[1,2,3] [[call]] some_func; // assert error
[1,2,3] call some_func; // assert error
[[1],"2",3] call some_func; // Alright!</code>
[[1],"2",3] call some_func; // Alright!
</sqf>


|seealso= [[try]] [[catch]] [[throw]] [[halt]] [[diag_captureFrame]] [[diag_captureSlowFrame]] [[diag_logSlowFrame]]
|seealso= [[try]] [[catch]] [[throw]] [[halt]] [[diag_captureFrame]] [[diag_captureSlowFrame]] [[diag_logSlowFrame]]

Revision as of 13:25, 17 May 2022

Hover & click on the images for description

Description

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. If script was pre-processed with preprocessFileLineNumbers, it will also show/log the error line number and the file name.
Groups:
Program Flow

Syntax

Syntax:
assert condition
Parameters:
condition: Boolean
Return Value:
Boolean - mirrors condition

Examples

Example 1:
assert (1 &gt; 2);
PreprocessFile.jpg
Example 2:
Check function params (Faster alternative to BIS_fnc_param)
some_func = { _0 = _this select 0; _1 = _this select 1; _2 = _this select 2; if (!assert ( typeName _0 == "ARRAY" && typeName _1 == "STRING" && typeName _2 == "SCALAR" )) exitWith { /* optional error logging */ }; hint "Alright!"; }; [1,2,3] call some_func; // assert error [[1],"2",3] call some_func; // Alright!

Additional Information

See also:
try catch throw halt diag_captureFrame diag_captureSlowFrame diag_logSlowFrame

Notes

Report bugs on the Feedback Tracker and/or discuss them on the Arma Discord or on the Forums.
Only post proven facts here! Add Note
Posted on May 15, 2010 - 0:01
Roehre
Returns false, if condition is false, and returns true, if condition is true.