DownloadFile: Difference between revisions
Jump to navigation
Jump to search
(Undo revision 29959 by Erdem kilic (talk)) |
No edit summary |
||
(8 intermediate revisions by 4 users not shown) | |||
Line 1: | Line 1: | ||
{{Client function}} | {{Client function}} | ||
__NOTOC__ | __NOTOC__ | ||
This function | {{New items|3.0140|1.4| | ||
This function ensures the requested resource file is correct and then triggers [[onClientFileDownloadComplete]]. If the file has been previously downloaded and the CRC matches, the file will not be downloaded again but [[onClientFileDownloadComplete]] will still run. The '''file''' should also be included in the resource meta.xml with the '''download''' attribute set to "false", see [[meta.xml]] for more details. | |||
}} | |||
{{Tip|If you are only using [[downloadFile]] to download mod files after other resources, then do not use [[downloadFile]], and instead set<br/> '<download_priority_group>-1</download_priority_group>' in the resource [[meta.xml]]}} | |||
{{Note|This function may cause performance issues with client and/or server.}} | |||
{{Tip|Avoid using fileExists before calling [[downloadFile]]. Always call [[downloadFile]] and handle the result in [[onClientFileDownloadComplete]]}} | |||
==Syntax== | ==Syntax== | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
Line 15: | Line 19: | ||
==Example== | ==Example== | ||
'''Example 1:''' This client side event downloads a file when the resource has started. | '''Example 1:''' This client side event downloads a file when the current resource has started. | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
-- the function is called | -- the function is called on resource start | ||
function | function onThisResourceStart ( ) | ||
downloadFile ( "test. | downloadFile ( "test.xml" ) | ||
end | end | ||
addEventHandler ( "onClientResourceStart", | addEventHandler ( "onClientResourceStart", resourceRoot, onThisResourceStart ) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
==See Also== | ==See Also== | ||
{{Client_utility_functions}} | {{Client_utility_functions}} |
Latest revision as of 00:41, 3 February 2017
This function ensures the requested resource file is correct and then triggers onClientFileDownloadComplete. If the file has been previously downloaded and the CRC matches, the file will not be downloaded again but onClientFileDownloadComplete will still run. The file should also be included in the resource meta.xml with the download attribute set to "false", see meta.xml for more details.
Tip: If you are only using downloadFile to download mod files after other resources, then do not use downloadFile, and instead set '<download_priority_group>-1</download_priority_group>' in the resource meta.xml |
Tip: Avoid using fileExists before calling downloadFile. Always call downloadFile and handle the result in onClientFileDownloadComplete |
Syntax
bool downloadFile ( string fileName )
Required Arguments
- fileName: A string referencing the name of the file to download
Returns
Returns true if file download has been queued, false otherwise.
Example
Example 1: This client side event downloads a file when the current resource has started.
-- the function is called on resource start function onThisResourceStart ( ) downloadFile ( "test.xml" ) end addEventHandler ( "onClientResourceStart", resourceRoot, onThisResourceStart )
See Also
- createTrayNotification
- downloadFile
- getDevelopmentMode
- getKeyboardLayout
- getLocalization
- isShowCollisionsEnabled
- isShowSoundEnabled
- isTransferBoxAlwaysVisible
- isTransferBoxVisible
- isTrayNotificationEnabled
- setClipboard
- setDevelopmentMode
- setTransferBoxVisible
- setWindowFlashing
- showCol
- showSound
- Shared
- addDebugHook
- base64Decode
- base64Encode
- debugSleep
- decodeString
- encodeString
- fromJSON
- generateKeyPair
- getColorFromString
- getDevelopmentMode
- getDistanceBetweenPoints2D
- getDistanceBetweenPoints3D
- getEasingValue
- getNetworkStats
- getNetworkUsageData
- getPerformanceStats
- getRealTime
- getTickCount
- getTimerDetails
- getTimers
- getFPSLimit
- getUserdataType
- getVersion
- gettok
- isTransferBoxVisible
- setTransferBoxVisible
- hash
- inspect
- interpolateBetween
- iprint
- isOOPEnabled
- isTimer
- killTimer
- md5
- passwordHash
- passwordVerify
- pregFind
- pregMatch
- pregReplace
- removeDebugHook
- resetTimer
- setDevelopmentMode
- setFPSLimit
- setTimer
- ref
- deref
- sha256
- split
- teaDecode
- teaEncode
- toJSON
- tocolor
- getProcessMemoryStats
- utfChar
- utfCode
- utfLen
- utfSeek
- utfSub
- bitAnd
- bitNot
- bitOr
- bitXor
- bitTest
- bitLRotate
- bitRRotate
- bitLShift
- bitRShift
- bitArShift
- bitExtract
- bitReplace