loadFile: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
(syntax format)
m (Add example and comments cleanup)
Line 6: Line 6:
|1.90|= Game version
|1.90|= Game version


|eff= local |= Effects in MP
____________________________________________________________________________________________
____________________________________________________________________________________________


| Return content of given filename. |= Description
| Return content of given filename as string. If you plan to [[compile]] said string, be aware that the file shouldn't contain comments or [[compile]] will throw an error. If there are comments, use [[preprocessFile]]/[[preprocessFileLineNumbers]] instead. |= Description
____________________________________________________________________________________________
____________________________________________________________________________________________


| '''loadFile''' filename |= Syntax
| [[loadFile]] fileName |= Syntax


|p1= filename: [[String]] |= Parameter 1
|p1= fileName: [[String]] |= Parameter 1


| [[String]] |= Return value
| [[String]] |= Return value
____________________________________________________________________________________________
____________________________________________________________________________________________
 
 
|x1= <code>_contents = [[loadFile]] "myFunction.sqf";</code> |= Example 1
|x1= <code>_contents = [[loadFile]] "wantedString.txt";</code> |= Example 1
 
|x2= <code>_contents = [[compile]] [[loadFile]] "myFunction.sqf"; {{codecomment|// will compile string into code}}</code> |= Example 2
____________________________________________________________________________________________
____________________________________________________________________________________________


| [[preprocessFileLineNumbers]], [[preprocessFile]] |= See also
| [[preprocessFile]], [[preprocessFileLineNumbers]] |= See also


}}
}}
Line 29: Line 30:
<dl class="command_description">
<dl class="command_description">
<!-- Note Section BEGIN -->
<!-- Note Section BEGIN -->
<dd class="notedate">Posted on 28 November 2006 - 01:37
<dt class="note">[[User:Pennywise|Pennywise]]<dd class="note">In Armed Assault, the 'loadfile' command must be preceded by the 'compile' command to work.
<br>
Ex OFP 1.96:  _falarmEvent = loadfile ("syswarn\falarmEvent.sqf")
<br>
Ex ArmA 1.0:  _falarmEvent = compile loadfile ("syswarn\falarmEvent.sqf")
</dd></dt></dd>
<dd class="notedate">Posted on 11 July 2007 - 01:10 (CEST)
<dt class="note">'''[[User:Tactii|Tactii]]'''<dd class="note">The note by [[User:Pennywise|Pennywise]] is not entirely accurate. [[loadFile]] only needs to be preceded with [[compile]] when loading [[Code|code]] (for example, a [[Function|function]] contained in an [[Script (File)|.sqf file]]). Using [[loadFile]] without [[compile]] will return a [[String|string]], which, in some cases, is exactly what you want.
</dd></dt></dd>
<dd class="notedate">Posted on 02 December 2012 - 11:17 (ZULU)
<dt class="note">'''[[neokika]]'''<dd class="note">Please note that any comment you have within the file you load will be included, to get around that use preprocessFile instead.
</dd></dt></dd>
<dd class="notedate">Posted on 25 January 2016 - 12:13
<dd class="notedate">Posted on 25 January 2016 - 12:13
<dt class="note">'''[[User:James|James]]'''<dd class="note">Notice that you will have to activate file patching via -filePatching  [[https://community.bistudio.com/wiki/Arma_3_Startup_Parameters|-filePatching]]. Otherwise, execVM and loadFile will *not* load any files outside your mission folder (like the global scripts). For more info see CMA:DevelopmentSetup (since Arma 3 1.49+).
<dt class="note">[[User:James|James]]
</dd></dt></dd>
<dd class="note">Notice that you will have to activate file patching via [[Arma_3_Startup_Parameters#Developer Options|-filePatching]]. Otherwise, execVM and loadFile will *not* load any files outside your mission folder (like the global scripts).
<!-- Note Section END -->
<!-- Note Section END -->
</dl>
</dl>


<h3 style="display:none">Bottom Section</h3>
<h3 style="display:none">Bottom Section</h3>
[[Category:Scripting Commands|LOADFILE]]
[[Category:Scripting Commands|{{uc:{{PAGENAME}}}}]]
[[Category:Command_Group:_System_Commands|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting Commands OFP 1.96|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting Commands OFP 1.99|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting Commands OFP 1.99|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting Commands OFP 1.96|LOADFILE]]
[[Category:Scripting Commands ArmA|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting Commands ArmA|LOADFILE]]
[[Category:Command_Group:_System_Commands|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting Commands ArmA2|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting Commands ArmA2|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting Commands Arma 3|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting Commands Arma 3|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting_Commands_Take_On_Helicopters|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting_Commands_Take_On_Helicopters|{{uc:{{PAGENAME}}}}]]

Revision as of 09:52, 3 April 2018

Hover & click on the images for description

Description

Description:
Return content of given filename as string. If you plan to compile said string, be aware that the file shouldn't contain comments or compile will throw an error. If there are comments, use preprocessFile/preprocessFileLineNumbers instead.
Groups:
Uncategorised

Syntax

Syntax:
loadFile fileName
Parameters:
fileName: String
Return Value:
String

Examples

Example 1:
_contents = loadFile "wantedString.txt";
Example 2:
_contents = compile loadFile "myFunction.sqf"; // will compile string into code

Additional Information

See also:
preprocessFilepreprocessFileLineNumbers

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

Notes

Posted on 25 January 2016 - 12:13
James
Notice that you will have to activate file patching via -filePatching. Otherwise, execVM and loadFile will *not* load any files outside your mission folder (like the global scripts).

Bottom Section