typeName: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Text replacement - " |r1=[[" to " |r1= [[")
m (Fix)
 
(64 intermediate revisions by the same user not shown)
Line 18: Line 18:
|gr1= Variables
|gr1= Variables


|descr= Returns the [[:Category:Data Types|data type]] of an expression.  
|descr= Returns the [[:Category:Data Types|Data Type]] of an expression.  


The type is returned as on of the following all-uppercase strings:
The type is returned as on of the following all-uppercase strings:
{{Columns|5|
* "[[Array|ARRAY]]"
* "[[Array|ARRAY]]"
* "[[Bool|BOOL]]"
* "[[Boolean|BOOL]]"
* "[[Code|CODE]]"
* "[[Code|CODE]]"
* "[[Config|CONFIG]]"
* "[[Config|CONFIG]]"
Line 28: Line 29:
* "[[Display|DISPLAY]]"
* "[[Display|DISPLAY]]"
* "[[Group|GROUP]]"
* "[[Group|GROUP]]"
* "[[Location|LOCATION]]"
* "[[Object|OBJECT]]"
* "[[Object|OBJECT]]"
* "[[Scalar|SCALAR]]"
* "[[Number|SCALAR]]" (and "[[Number|NaN]]")
* "[[Script|SCRIPT]]"
* "[[Script Handle|SCRIPT]]"
* "[[Side|SIDE]]"
* "[[Side|SIDE]]"
* "[[String|STRING]]"
* "[[String|STRING]]"
* "[[Text|TEXT]]"
* "[[Structured Text|TEXT]]"
* "[[Team Member|TEAM_MEMBER]]"
* {{GVI|arma1|1.08|size= 0.75}} "[[Location|LOCATION]]"
* "[[Namespace|NAMESPACE]]"
* {{GVI|arma2|1.00|size= 0.75}} "[[Team Member|TEAM_MEMBER]]"
* "[[Diary Record|DIARY_RECORD]]"
* {{GVI|arma2|1.00|size= 0.75}} "[[Namespace|NAMESPACE]]"
* "[[Task|TASK]]"
* {{GVI|arma2|1.00|size= 0.75}} "[[Diary Record|DIARY_RECORD]]"
* "[[HashMap|HASHMAP]]"
* {{GVI|arma2|1.00|size= 0.75}} "[[Task|TASK]]"
They represent the available [[Data_Types|data types]] in Arma.
* {{GVI|arma3|2.02|size= 0.75}} "[[HashMap|HASHMAP]]"
{{Feature|Informative|For comparing types, use [[isEqualType]] command instead in {{arma3}}}}
}}
They represent the available [[:Category:Data Types|Data Types]] in {{arma}}.
{{Feature|arma3|For type comparison, use [[isEqualType]] command instead.}}


|s1= [[typeName]] anything
|s1= [[typeName]] anything
Line 49: Line 51:
|r1= [[String]]
|r1= [[String]]


|x1= <code>_msg = "hello"; _result = [[typeName]] _msg;  //_result will be "STRING"</code>
|x1= <sqf>_msg = "hello"; _result = typeName _msg;  //_result will be "STRING"</sqf>
|x2= <code>_unit = [[player]]; _result = [[typeName]] _unit; //_result becomes "OBJECT"</code>


|x3= Values representing direct [[:Category: Data Types| Data Types]]:<code>[[hint]] [[typeName]] 0; //SCALAR
|x2= <sqf>_unit = player; _result = typeName _unit; //_result becomes "OBJECT"</sqf>
[[hint]] [[typeName]] ""; //STRING
[[hint]] [[typeName]] [[true]]; //BOOL
[[hint]] [[typeName]] []; //ARRAY
[[hint]] [[typeName]] {}; //CODE
[[hint]] [[typeName]] [[objNull]]; //OBJECT
[[hint]] [[typeName]] [[grpNull]]; //GROUP
[[hint]] [[typeName]] [[controlNull]]; //CONTROL
[[hint]] [[typeName]] [[teamMemberNull]]; //TEAM_MEMBER
[[hint]] [[typeName]] [[displayNull]]; //DISPLAY
[[hint]] [[typeName]] [[taskNull]]; //TASK
[[hint]] [[typeName]] [[locationNull]]; //LOCATION
[[hint]] [[typeName]] [[sideUnknown]]; //SIDE
[[hint]] [[typeName]] [[text]] ""; //TEXT
[[hint]] [[typeName]] [[configFile]]; //CONFIG
[[hint]] [[typeName]] [[configNull]]; //CONFIG (Since Arma 3 v1.54)
[[hint]] [[typeName]] [[missionNamespace]]; //NAMESPACE
[[hint]] [[typeName]] [[diaryRecordNull]]; //DIARY_RECORD (Since Arma 3 v2.00)
[[hint]] [[typeName]] [[createHashMap]]; //HASHMAP (Since Arma 3 v2.02)</code>


|x4= <code>[[if]] ([[typeName]] _this [[!=]] "ARRAY") [[exitWith]] {
|x3= Values representing direct [[:Category:Data Types|Data Types]]:
[[hint]] "_this is not an array!"
<sqf>
}
hint typeName 0; // SCALAR
//is the same as
hint typeName 1e39; // NaN
[[if]] ([[typeName]] _this [[!=]] [[typeName]] []) [[exitWith]] {
hint typeName ""; // STRING
[[hint]] "_this is not an array!"
hint typeName true; // BOOL
}
hint typeName []; // ARRAY
//same result but faster in {{arma3}}
hint typeName {}; // CODE
[[if]] !(_this [[isEqualType]] []) [[exitWith]] {
hint typeName scriptNull; // SCRIPT (since {{arma3}} v1.32)
[[hint]] "_this is not an array!"
hint typeName objNull; // OBJECT
</code>
hint typeName grpNull; // GROUP
hint typeName controlNull; // CONTROL
hint typeName teamMemberNull; // TEAM_MEMBER (since {{arma2}} v1.00)
hint typeName displayNull; // DISPLAY
hint typeName taskNull; // TASK (since {{arma2}} v1.00)
hint typeName locationNull; // LOCATION
hint typeName sideUnknown; // SIDE
hint typeName text ""; // TEXT
hint typeName configFile; // CONFIG
hint typeName configNull; // CONFIG (since {{arma3}} v1.54)
hint typeName missionNamespace; // NAMESPACE
hint typeName diaryRecordNull; // DIARY_RECORD (since {{arma3}} v2.00)
hint typeName createHashMap; // HASHMAP (since {{arma3}} v2.02)
</sqf>


|seealso= [[isEqualTypeAll]], [[isEqualType]], [[isEqualTypeParams]], [[isEqualTypeArray]], [[isEqualTypeAny]], [[typeOf]], [[isKindOf]], [[isClass]], [[isArray]], [[isNumber]], [[isText]], [[isNil]], [[isNull]]
|x4= <sqf>
if (typeName _this != "ARRAY") exitWith { hint "_this is not an array!" };
// is the same as
if (typeName _this != typeName []) exitWith { hint "_this is not an array!" };
// same result but faster in {{arma3}}
if !(_this isEqualType []) exitWith { hint "_this is not an array!" };
</sqf>
 
|seealso= [[isEqualTypeAll]] [[isEqualType]] [[isEqualTypeParams]] [[isEqualTypeArray]] [[isEqualTypeAny]] [[typeOf]] [[isKindOf]] [[isClass]] [[isArray]] [[isNumber]] [[isText]] [[isNil]] [[isNull]]
}}
}}


 
{{Note
<dl class="command_description">
|user= Killzone_Kid
 
|timestamp= 20160925111400
<dt></dt>
|text= [[typeName]] of [[nil]] is {{hl|ANY}}, however this is not possible to test as script command is just ignored when any argument is [[nil]].
<dd class="notedate">Posted on September 25, 2016 - 11:14 (UTC)</dd>
}}
<dt class="note">[[User:Killzone Kid|Killzone Kid]]</dt>
<dd class="note">
[[typeName]] of [[nil]] is <tt>ANY</tt>, however this is not possible to test as script command is just ignored when any argument is [[nil]]
</dd>
 
</dl>

Latest revision as of 17:16, 28 September 2024

Hover & click on the images for description

Description

Description:
Returns the Data Type of an expression. The type is returned as on of the following all-uppercase strings:

They represent the available Data Types in Arma.

Arma 3
For type comparison, use isEqualType command instead.
Groups:
Variables

Syntax

Syntax:
typeName anything
Parameters:
anything: Anything
Return Value:
String

Examples

Example 1:
_msg = "hello"; _result = typeName _msg; //_result will be "STRING"
Example 2:
_unit = player; _result = typeName _unit; //_result becomes "OBJECT"
Example 3:
Values representing direct Data Types:
hint typeName 0; // SCALAR hint typeName 1e39; // NaN hint typeName ""; // STRING hint typeName true; // BOOL hint typeName []; // ARRAY hint typeName {}; // CODE hint typeName scriptNull; // SCRIPT (since Arma 3 v1.32) hint typeName objNull; // OBJECT hint typeName grpNull; // GROUP hint typeName controlNull; // CONTROL hint typeName teamMemberNull; // TEAM_MEMBER (since Arma 2 v1.00) hint typeName displayNull; // DISPLAY hint typeName taskNull; // TASK (since Arma 2 v1.00) hint typeName locationNull; // LOCATION hint typeName sideUnknown; // SIDE hint typeName text ""; // TEXT hint typeName configFile; // CONFIG hint typeName configNull; // CONFIG (since Arma 3 v1.54) hint typeName missionNamespace; // NAMESPACE hint typeName diaryRecordNull; // DIARY_RECORD (since Arma 3 v2.00) hint typeName createHashMap; // HASHMAP (since Arma 3 v2.02)
Example 4:
if (typeName _this != "ARRAY") exitWith { hint "_this is not an array!" }; // is the same as if (typeName _this != typeName []) exitWith { hint "_this is not an array!" }; // same result but faster in Arma 3 if !(_this isEqualType []) exitWith { hint "_this is not an array!" };

Additional Information

See also:
isEqualTypeAll isEqualType isEqualTypeParams isEqualTypeArray isEqualTypeAny typeOf isKindOf isClass isArray isNumber isText isNil isNull

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
Killzone_Kid - c
Posted on Sep 25, 2016 - 11:14 (UTC)
typeName of nil is ANY, however this is not possible to test as script command is just ignored when any argument is nil.