<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.multitheftauto.com/wiki/Modules/FileSystem/file/readBoolean?action=history&amp;feed=atom</id>
	<title>Modules/FileSystem/file/readBoolean - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.multitheftauto.com/wiki/Modules/FileSystem/file/readBoolean?action=history&amp;feed=atom"/>
	<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=Modules/FileSystem/file/readBoolean&amp;action=history"/>
	<updated>2026-04-06T11:25:06Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.39.3</generator>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=Modules/FileSystem/file/readBoolean&amp;diff=73742&amp;oldid=prev</id>
		<title>Danilo at 03:04, 23 January 2022</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=Modules/FileSystem/file/readBoolean&amp;diff=73742&amp;oldid=prev"/>
		<updated>2022-01-23T03:04:44Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 03:04, 23 January 2022&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l1&quot;&gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;pageclass class=&quot;#3cc882&quot; subcaption=&quot;File function&quot;&gt;&amp;lt;/pageclass&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;__NOTOC__&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;__NOTOC__&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;This function attempts to read a boolean (native type) from a file and return it. The amount of bytes read should be one.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;This function attempts to read a boolean (native type) from a file and return it. The amount of bytes read should be one.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key wiki-wiki_dev_:diff::1.12:old-73658:rev-73742 --&gt;
&lt;/table&gt;</summary>
		<author><name>Danilo</name></author>
	</entry>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=Modules/FileSystem/file/readBoolean&amp;diff=73658&amp;oldid=prev</id>
		<title>Danilo: Created page with &quot;__NOTOC__ This function attempts to read a boolean (native type) from a file and return it. The amount of bytes read should be one.  ==Syntax== &lt;syntaxhighlight lang=&quot;lua&quot;&gt; boolean file:readBoolean () &lt;/syntaxhighlight&gt;  ==Returns== Returns a boolean if it was successfully read from the file, '''nil''' otherwise.  ==Example== &lt;section name=&quot;Client&quot; class=&quot;client&quot; show=&quot;true&quot;&gt; This snippet demonstrates a variable file format that stores player properties depending on whet...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=Modules/FileSystem/file/readBoolean&amp;diff=73658&amp;oldid=prev"/>
		<updated>2022-01-19T03:37:27Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;__NOTOC__ This function attempts to read a boolean (native type) from a file and return it. The amount of bytes read should be one.  ==Syntax== &amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt; boolean file:readBoolean () &amp;lt;/syntaxhighlight&amp;gt;  ==Returns== Returns a boolean if it was successfully read from the file, &amp;#039;&amp;#039;&amp;#039;nil&amp;#039;&amp;#039;&amp;#039; otherwise.  ==Example== &amp;lt;section name=&amp;quot;Client&amp;quot; class=&amp;quot;client&amp;quot; show=&amp;quot;true&amp;quot;&amp;gt; This snippet demonstrates a variable file format that stores player properties depending on whet...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;__NOTOC__&lt;br /&gt;
This function attempts to read a boolean (native type) from a file and return it. The amount of bytes read should be one.&lt;br /&gt;
&lt;br /&gt;
==Syntax==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
boolean file:readBoolean ()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Returns==&lt;br /&gt;
Returns a boolean if it was successfully read from the file, '''nil''' otherwise.&lt;br /&gt;
&lt;br /&gt;
==Example==&lt;br /&gt;
&amp;lt;section name=&amp;quot;Client&amp;quot; class=&amp;quot;client&amp;quot; show=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
This snippet demonstrates a variable file format that stores player properties depending on whether they are required.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local function saveLocalPlayerState( theFile, saveDetails )&lt;br /&gt;
    local player = localPlayer;&lt;br /&gt;
&lt;br /&gt;
    -- Write basic details about the player instance.&lt;br /&gt;
    theFile:writeShort( getElementModel( player ) );&lt;br /&gt;
    theFile:writeInt( getPlayerMoney() );&lt;br /&gt;
    &lt;br /&gt;
    -- Next write down special details given by the game.&lt;br /&gt;
    local isQuickSave = saveDetails.isQuickSave and true or false;&lt;br /&gt;
&lt;br /&gt;
    theFile:writeBoolean( isQuickSave );&lt;br /&gt;
&lt;br /&gt;
    if not ( isQuickSave ) then&lt;br /&gt;
        -- Save things like player position, dimension and interior.&lt;br /&gt;
        local posX, posY, posZ = getElementPosition( player );&lt;br /&gt;
        local dimension, interior = getElementDimension( player ), getElementInterior( player );&lt;br /&gt;
&lt;br /&gt;
        theFile:writeDouble( posX ); theFile:writeDouble( posY ); theFile:writeDouble( posZ );&lt;br /&gt;
        theFile:writeShort( dimension ); theFile:writeShort( interior );&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    -- Save the time this snapshot was taken.&lt;br /&gt;
    local realTime = getRealTime();&lt;br /&gt;
&lt;br /&gt;
    theFile:writeShort( realTime.minute ); theFile:writeShort( realTime.hour );&lt;br /&gt;
    theFile:writeShort( realTime.monthday ); theFile:writeShort( realTime.month + 1 ); theFile:writeShort( realTime.year + 1900 );&lt;br /&gt;
    return true;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function readBasicData( obj, operator, callback )&lt;br /&gt;
    local data = operator(obj);&lt;br /&gt;
&lt;br /&gt;
    if ( data ) then&lt;br /&gt;
        callback( data );&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- Function to restore details from a snapshot file stream.&lt;br /&gt;
local function loadLocalPlayerState( theFile )&lt;br /&gt;
    local player = localPlayer;&lt;br /&gt;
    local saveDetails = {};&lt;br /&gt;
&lt;br /&gt;
    -- Restore the basic information.&lt;br /&gt;
    readBasicData( theFile, theFile.readShort, function(model) setElementModel( player, model ); end );&lt;br /&gt;
    readBasicData( theFile, theFile.readInt, function(money) setPlayerMoney(money); end );&lt;br /&gt;
&lt;br /&gt;
    -- Read advanced parameters,&lt;br /&gt;
    local isQuickSave = theFile:readBoolean();&lt;br /&gt;
    saveDetails.isQuickSave = isQuickSave;&lt;br /&gt;
&lt;br /&gt;
    if not ( isQuickSave ) then&lt;br /&gt;
        -- Restore advanced details.&lt;br /&gt;
        local posX, posY, posZ = theFile:readDouble(), theFile:readDouble(), theFile:readDouble();&lt;br /&gt;
        local dimension, interior = theFile:readShort(), theFile:readShort();&lt;br /&gt;
&lt;br /&gt;
        -- Set them, if read correctly.&lt;br /&gt;
        if ( interior ) then&lt;br /&gt;
            setElementPosition( player, posX, posY, posZ );&lt;br /&gt;
            setElementDimension( player, dimension );&lt;br /&gt;
            setElementInterior( player, interior );&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    -- Get the time the snapshot was taken at.&lt;br /&gt;
    saveDetails.saveTime = {&lt;br /&gt;
        minute = theFile:readShort(),&lt;br /&gt;
        hour = theFile:readShort(),&lt;br /&gt;
        monthday = theFile:readShort(),&lt;br /&gt;
        month = theFile:readShort(),&lt;br /&gt;
        year = theFile:readShort()&lt;br /&gt;
    };&lt;br /&gt;
&lt;br /&gt;
    -- Return the save details so the runtime can react accordingly.&lt;br /&gt;
    return saveDetails;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- Command to save a complete snapshot of the player.&lt;br /&gt;
addCommandHandler( &amp;quot;save&amp;quot;,&lt;br /&gt;
    function()&lt;br /&gt;
        local saveDetails =&lt;br /&gt;
        {&lt;br /&gt;
            isQuickSave = false&lt;br /&gt;
        };&lt;br /&gt;
&lt;br /&gt;
        local saveFile = fileCreate( &amp;quot;savestate.dat&amp;quot; );&lt;br /&gt;
&lt;br /&gt;
        if ( saveFile ) then&lt;br /&gt;
            saveLocalPlayerState( saveFile, saveDetails );&lt;br /&gt;
&lt;br /&gt;
            saveFile:'''Bold text'''destroy();&lt;br /&gt;
&lt;br /&gt;
            outputChatBox( &amp;quot;successfully saved complete player status&amp;quot; );&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
);&lt;br /&gt;
&lt;br /&gt;
-- Command to save a quick savestate.&lt;br /&gt;
addCommandHandler( &amp;quot;qsave&amp;quot;,&lt;br /&gt;
    function()&lt;br /&gt;
        local saveDetails =&lt;br /&gt;
        {&lt;br /&gt;
            isQuickSave = true&lt;br /&gt;
        };&lt;br /&gt;
&lt;br /&gt;
        local saveFile = fileCreate( &amp;quot;savestate.dat&amp;quot; );&lt;br /&gt;
&lt;br /&gt;
        if ( saveFile ) then&lt;br /&gt;
            saveLocalPlayerState( saveFile, saveDetails );&lt;br /&gt;
&lt;br /&gt;
            saveFile:destroy();&lt;br /&gt;
&lt;br /&gt;
            outputChatBox( &amp;quot;successfully saved quick player status&amp;quot; );&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
);&lt;br /&gt;
&lt;br /&gt;
-- Command to load a savestate from disk.&lt;br /&gt;
addCommandHandler( &amp;quot;loadstate&amp;quot;,&lt;br /&gt;
    function()&lt;br /&gt;
        if not ( fileExists( &amp;quot;savestate.dat&amp;quot; ) ) then&lt;br /&gt;
            return;&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        local saveFile = fileOpen( &amp;quot;savestate.dat&amp;quot; );&lt;br /&gt;
&lt;br /&gt;
        if ( saveFile ) then&lt;br /&gt;
            local saveData = loadLocalPlayerState( saveFile );&lt;br /&gt;
&lt;br /&gt;
            saveFile:destroy();&lt;br /&gt;
&lt;br /&gt;
            outputChatBox( &amp;quot;restored from a save (date was &amp;quot; .. saveData.saveTime.monthday .. &amp;quot;.&amp;quot; .. saveData.saveTime.month .. &amp;quot;.&amp;quot; .. saveData.saveTime.year .. &amp;quot;)&amp;quot; );&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/section&amp;gt;&lt;br /&gt;
{{:Modules/FileSystem/file/functions}}&lt;/div&gt;</summary>
		<author><name>Danilo</name></author>
	</entry>
</feed>