<?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_15";
<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_save_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_save_async"/>
<meta name="rh-index-keywords" content="buffer_save_async"/>
<meta name="search-keywords" content="buffer_save_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_save_async">
<span>buffer_save_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_save_async</h1>
<p>With this function you can save part of the contents of a buffer to a file, ready to be read back into memory using the <a href="buffer_load.htm"><tt>buffer_load()</tt></a> function (or any of the other functions for loading buffers). The "offset"
defines the start position within the buffer for saving (in bytes), and the "size" is the size of the buffer area to be saved from that offset onwards (also in bytes). This function works asynchronously, and so the game will continue running
while being saved, and all files saved using this function will be placed in a "default" folder. This folder does <i>not</i> need to be included in the filename as it is added automatically by GameMaker. For example the filename path "<tt>Data\Player_Save.sav</tt>"
would actually be saved to "<tt>default\Data\Player_Save.sav</tt>". However, if you then load the file using the function <a href="buffer_load_async.htm"><tt>buffer_load_async()</tt></a>, you do not need to supply the "default"
part of the path either (but any other file function <i>will</i> require it, except on consoles Xbox One, PS4 and Nintendo Switch).</p>
<p>The function will return a unique ID value and trigger an <a href="../../../The_Asset_Editors/Object_Properties/Async_Events/Save_Load.htm">Asynchronous Save/Load Event</a> where you can use the returned ID to check the <tt>async_load</tt> ID value,
as shown in the extended example below. The <a href="../../GML_Overview/Variables/Builtin_Global_Variables/async_load.htm"><tt>async_load</tt></a> map in the event will have the following two key/value pairs:</p>
<ul>
<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>Note that you can save out multiple buffers in one by calling this function multiple times between calls to <a href="buffer_async_group_begin.htm"><tt>buffer_async_group_begin()</tt></a> and <a href="buffer_async_group_end.htm"><tt>buffer_async_group_end()</tt></a> (see those functions for further information on this).</p>
<p> </p>
<h4>Syntax:</h4>
<p class="code">buffer_save_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 save.</td>
</tr>
<tr>
<td>filename</td>
<td>The name of the file to save as.</td>
</tr>
<tr>
<td>offset</td>
<td>The offset within the buffer to save from (in bytes).</td>
</tr>
<tr>
<td>size</td>
<td>The size of the buffer area to save (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_save_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">saveid = buffer_save_async(buff, "Player_Save.sav", 0, 16384);</p>
<p>The above code saves the contents of the buffer "<i>buff</i>" to the given save file, storing the ID of the function call in the variable "<i>saveid</i>". When the save 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") == saveid<br/> {
<br/> if ds_map_find_value(async_load, "status") == false<br/> {
<br/> show_debug_message("Save 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>
<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.htm">buffer_load</a></div>
</div>
</div>
<h5>© Copyright YoYo Games Ltd. 2020 All Rights Reserved</h5>
</div>
</body></html>