<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<script type="text/javascript" language="JavaScript">
function reDo() {
if (innerWidth != origWidth || innerHeight != origHeight)
location.reload();
}
if ((parseInt(navigator.appVersion) == 4) && (navigator.appName == "Netscape")) {
origWidth = innerWidth;
origHeight = innerHeight;
onresize = reDo;
}
onerror = null;
</script>
<style type="text/css">
< !-- div.WebHelpPopupMenu {
position: absolute;
left: 0px;
top: 0px;
z-index: 4;
visibility: hidden;
}
p.WebHelpNavBar {
text-align: right;
}
-->
</style>
<script type="text/javascript">
gRootRelPath = "../../..";
gCommonRootRelPath = "../../..";
gTopicId = "9.2.17.0_18";
<script type="text/javascript" src="../../../template/scripts/rh.min.js"></script>
<script type="text/javascript" src="../../../template/scripts/common.min.js"></script>
<script type="text/javascript" src="../../../template/scripts/topic.min.js"></script>
<script type="text/javascript" src="../../../template/scripts/topicwidgets.min.js"></script>
<script type="text/javascript" src="../../../whxdata/projectsettings.js"></script>
<link rel="stylesheet" type="text/css" href="../../../template/styles/topic.min.css"/>
<link rel="stylesheet" type="text/css" href="../../../template/Charcoal_Grey/topicheader.css"/>
<meta name="topic-status" content="Draft"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>buffer_load_async</title>
<meta name="generator" content="Adobe RoboHelp 2019"/>
<link rel="stylesheet" href="../../../assets/css/default.css" type="text/css"/>
<meta name="rh-authors" content="Mark Alexander"/>
<meta name="topic-comment" content="Reference page for buffer_load_async"/>
<meta name="rh-index-keywords" content="buffer_load_async"/>
<meta name="search-keywords" content="buffer_load_async"/>
</head>
<body>
<div class="topic-header rh-hide" id="rh-topic-header" onclick="rh._.goToFullLayout()">
<div class="logo">
</div>
<div class="nav">
<div class="title" title="buffer_load_async">
<span>buffer_load_async</span>
</div>
<div class="gotohome" title="Click here to see this page in full context">
<span>Click here to see this page in full context</span>
</div>
</div>
</div>
<div class="topic-header-shadow rh-hide" id="rh-topic-header-shadow"></div>
<h1>buffer_load_async</h1>
<p>With this function you can load a file that you have created previously using the <a href="buffer_save.htm"><tt>buffer_save()</tt></a> function (or any of the other functions for saving buffers) into a buffer. The "offset" defines the start
position within the buffer for loading (in bytes), and the "size" is the size of the buffer area to be loaded from that offset onwards (also in bytes). You can supply a value of -1 for the size argument and the entire buffer will be loaded.
Note that the function will load from a "default" folder, which does <i>not</i> need to be included as part of the file path you provide. This folder will be created if it doesn't exist or when you save a file using <a href="buffer_save_async.htm"><tt>buffer_save_async()</tt></a>.</p>
<p>The function returns a unique ID value which can then be used in the <a href="../../../The_Asset_Editors/Object_Properties/Async_Events/Save_Load.htm">Save / Load Asynchronous event</a> to check the <a href="../../GML_Overview/Variables/Builtin_Global_Variables/async_load.htm"><tt>async_load</tt></a> ID value, as shown in the extended example below. The <tt>async_load</tt> map in the event will have the following two key/value pairs:</p>
<ul class="colour">
<li><b>"id": </b>the ID of the async function as returned by the save function.</li>
<li><b>"status": </b>will return <tt>true</tt> if the data was saved/loaded correctly, and <tt>false</tt> otherwise.</li>
</ul>
<p class="note"><b>NOTE</b>: On <b>HTML5</b>, this is the preferred method for loading a file if you are loading from a server and not local storage, as loading synchronously has been deprecated on most browsers and will eventually be obsoleted.</p>
<p> </p>
<h4>Syntax:</h4>
<p class="code">buffer_load_async(buffer, filename, offset, size);</p>
<table>
<tbody>
<tr>
<th>Argument</th>
<th>Description</th>
</tr>
<tr>
<td>buffer</td>
<td>The index of the buffer to load.</td>
</tr>
<tr>
<td>filename</td>
<td>The name of the file to load.</td>
</tr>
<tr>
<td>offset</td>
<td>The offset within the buffer to load to (in bytes).</td>
</tr>
<tr>
<td>size</td>
<td>The size of the buffer area to load (in bytes).</td>
</tr>
</tbody>
</table>
<p> </p>
<h4>Returns:</h4>
<p class="code">Real</p>
<p> </p>
<h4>Extended Example:</h4>
<p>The <tt>buffer_load_async()</tt> function can be called from any event, and since it is asynchronous the callback can be almost instantaneous or could take several seconds. Calling the function is simple and would look something like this:</p>
<p class="code">loadid = buffer_load_async(buff, "Player_Save.sav", 0, 16384);</p>
<p>The above code loads the contents of the file "<i>Player_Save.sav</i>" to the given buffer, storing the ID of the function call in the variable "<i>loadid</i>". When the load is complete, the asynchronous Save/Load event will be
triggered and you can parse the <tt>async_load</tt> map for the correct ID of the function, like this:</p>
<p class="code">if ds_map_find_value(async_load, "id") == loadid<br/> {
<br/> if ds_map_find_value(async_load, "status") == false<br/> {
<br/> show_debug_message("Load failed!");<br/> }
<br/> }
</p>
<p>The above code will first check the ID of the DS map that has been created, then check the status of the callback, posting a debug message if there has been any issues.</p>
<p> </p>
<p> </p>
<div class="footer">
<div class="buttons">
<div class="clear">
<div style="float:left">Back: <a href="Buffers.htm">Buffers</a></div>
<div style="float:right">Next: <a href="buffer_load_partial.htm">buffer_load_partial</a></div>
</div>
</div>
<h5>© Copyright YoYo Games Ltd. 2020 All Rights Reserved</h5>
</div>
</body></html>