<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Savegame data implimentation in Stingray Forum (Read Only)</title>
    <link>https://forums.autodesk.com/t5/stingray-forum-read-only/savegame-data-implimentation/m-p/6494712#M5632</link>
    <description>&lt;P&gt;You can call close() anytime after the loading has completed, and after you have copied its token.data.&lt;/P&gt;
&lt;P&gt;Generally it's better to do this as soon as possible, since you won't need that token for anything after you've pulled out its data.&lt;/P&gt;</description>
    <pubDate>Thu, 11 Aug 2016 16:24:14 GMT</pubDate>
    <dc:creator>_robbs_</dc:creator>
    <dc:date>2016-08-11T16:24:14Z</dc:date>
    <item>
      <title>Savegame data implimentation</title>
      <link>https://forums.autodesk.com/t5/stingray-forum-read-only/savegame-data-implimentation/m-p/6492057#M5602</link>
      <description>&lt;P&gt;Hi everyone hope everyone is fine. I found some lua code based of save game data that i can hookup to the flownodes. but thing is where do i define the location to save the savegamedata.. i know I can save the table of any type of data numeric, boolean,strings,ids,vectors do i need to specify. the table for each data type and then stores these content tables to another table that goes in to savegame file. and how to retrieve these tables any indications is quite helpful. i got some hints but little is appreciated.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Aug 2016 16:20:39 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/stingray-forum-read-only/savegame-data-implimentation/m-p/6492057#M5602</guid>
      <dc:creator>Shanii2</dc:creator>
      <dc:date>2016-08-10T16:20:39Z</dc:date>
    </item>
    <item>
      <title>Re: Savegame data implimentation</title>
      <link>https://forums.autodesk.com/t5/stingray-forum-read-only/savegame-data-implimentation/m-p/6492745#M5608</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you're using the `stingray.SaveSystem` API, the directory is set by the &amp;lt;platform&amp;gt;.save_dir key in the settings.ini file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;win32 = {
    save_dir = "C:\whatever"
}&lt;/PRE&gt;
&lt;P&gt;This applies to Windows and iOS. It doesn't seem like that SaveSystem API is implemented on Android.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Aug 2016 20:22:58 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/stingray-forum-read-only/savegame-data-implimentation/m-p/6492745#M5608</guid>
      <dc:creator>_robbs_</dc:creator>
      <dc:date>2016-08-10T20:22:58Z</dc:date>
    </item>
    <item>
      <title>Re: Savegame data implimentation</title>
      <link>https://forums.autodesk.com/t5/stingray-forum-read-only/savegame-data-implimentation/m-p/6492762#M5609</link>
      <description>&lt;P&gt;There are a few special strings that you can use in the value, which will get expanded automatically&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;STRONG&gt;%APPDATA%&lt;/STRONG&gt;: The folder for user storage in Windows.&lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;%SAVEDATA%&lt;/STRONG&gt;: The folder for user storage in iOS.&lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;%HOSTNAME%&lt;/STRONG&gt;: The name of the computer.&lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;%DATE% or %UTCDATE%&lt;/STRONG&gt;: The local or UTC date on the form YYYY-MM-DD.&lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;%TIME% or %UTCTIME%&lt;/STRONG&gt;: The local or UTC time on the form HH.MM.SS.&lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;%RANDOM%&lt;/STRONG&gt;: Eight random letters.&lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;%SESSION%&lt;/STRONG&gt;: Random hexadecimal string identifying this play session. This can be used to match different logs from same play session.&lt;/LI&gt;
&lt;LI&gt;&lt;SPAN class="pl-s"&gt;&lt;SPAN class="pl-c1"&gt;%S&lt;/SPAN&gt;TEAMUSER&lt;SPAN class="pl-ii"&gt;%&lt;/SPAN&gt;&lt;/SPAN&gt; for your user data folder if you're using Steam.&lt;/LI&gt;
&lt;/UL&gt;</description>
      <pubDate>Wed, 10 Aug 2016 20:28:05 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/stingray-forum-read-only/savegame-data-implimentation/m-p/6492762#M5609</guid>
      <dc:creator>_robbs_</dc:creator>
      <dc:date>2016-08-10T20:28:05Z</dc:date>
    </item>
    <item>
      <title>Re: Savegame data implimentation</title>
      <link>https://forums.autodesk.com/t5/stingray-forum-read-only/savegame-data-implimentation/m-p/6493492#M5616</link>
      <description>&lt;P&gt;Thanks and can you give a bit of hint how to save the game data in form of tables and to retrieve that data back... &amp;nbsp;because game data can be consist of number of things like. current score. achievement unlocked in form of boolean . special ids of things. the previous level as string. current position of character and current situation in the form of some sort of boolean or string.. &amp;nbsp;i know i can create a table for each data type that can be saved but again how to retrieve&amp;nbsp;the table back from saved data because the global variables only retains data during runtime.&lt;/P&gt;</description>
      <pubDate>Thu, 11 Aug 2016 07:33:51 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/stingray-forum-read-only/savegame-data-implimentation/m-p/6493492#M5616</guid>
      <dc:creator>Shanii2</dc:creator>
      <dc:date>2016-08-11T07:33:51Z</dc:date>
    </item>
    <item>
      <title>Re: Savegame data implimentation</title>
      <link>https://forums.autodesk.com/t5/stingray-forum-read-only/savegame-data-implimentation/m-p/6493895#M5620</link>
      <description>&lt;P&gt;Basically you're responsible for putting together a table that contains all the data you need for your game. So, for example, your table might contain a matrix for the player's last position/rotation in the world, a number that indicates the last level the player was on, and a table for each level in the game that contains a boolean value for each inventory item that the player can collect, to indicate whether it's been found.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Once you have your data ready, you call&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;stingray.SaveSystem.auto_save("filename", table)&lt;/FONT&gt;&lt;BR /&gt;to record your table to a file. As mentioned earlier, this gets saved to the location you set in the settings.ini file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When you need to restore a game from saved data, you call&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;token = stingray.SaveSystem.auto_load("filename")&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;to get the data back from the file. This function returns a "token" ID that identifies your request.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This call is *asynchronous*, which means that it may take several frames to finish loading. So, after you call auto_load, you have to call&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;local progress_data = stingray.SaveSystem.progress(token)&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;and pass it your loading token. This function returns a table that tells you when the saved data is fully loaded. When &lt;FONT face="courier new,courier"&gt;progress.done&lt;/FONT&gt; is true, then you can get back the table you originally saved in your call to &lt;FONT face="courier new,courier"&gt;auto_save&lt;/FONT&gt; from &lt;FONT face="courier new,courier"&gt;progress.data&lt;/FONT&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's some code from an example project that shows it in practice.&lt;/P&gt;
&lt;P&gt;First, the table is set up in SaveManager.data.&lt;/P&gt;
&lt;P&gt;Every time the player completes a level, SaveManager.needToSave is set to true, and the next frame update the SaveManager.save_file function gets called, which calls SaveSystem.auto_save().&lt;/P&gt;
&lt;P&gt;Every time a new game is started and the save system is initialized, it tries to load the same file in SaveManager.init. It saves the token in SaveManager.token. Then, each update, SaveManager.onProgress calls SaveSystem.progress() to check how the load is progressing. If the request is finished, and it has data, then it copies that data back to SaveManager.data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Project.SaveManager = Project.SaveManager or {}

local SaveSystem = stingray.SaveSystem
local SaveManager = Project.SaveManager

SaveManager.data = SaveManager.data or {}

SaveManager.initDone = false
SaveManager.isFirst = true

SaveManager.needToSave = false

function SaveManager.enabled()
    return SaveSystem.exists()
end

function SaveManager.init()
    if not SaveManager.initDone then
        SaveManager.create_empty_data()
        if SaveManager.enabled() then
             print("Save Manager is ENABLED")
             SaveManager.load_file()
        else
            print("Save Manager is DISABLED")
        end
        SaveManager.initDone = true
    end
end

function SaveManager.create_empty_data()
    for nameCount = 1, 20 do
        SaveManager.data["Level_"..nameCount] = {
	                ["big_star_taken"] = false,
	                ["stars"] = 0,
	                ["locked"] = true
	   }
    end

    SaveManager.data["Level_1"]["locked"] = false
end

function SaveManager.is_level_locked(levelNumber)
    if not SaveManager.enabled() then return false end
    return SaveManager.data["Level_"..levelNumber]["locked"]
end
function SaveManager.is_star_collected(levelNumber)
    if not SaveManager.enabled() then return false end
    return SaveManager.data["Level_"..levelNumber]["big_star_taken"]
end

function SaveManager.get_stars_collected(levelNumber)
    if not SaveManager.enabled() then return 0 end
    return SaveManager.data["Level_"..levelNumber]["stars"]
end

function SaveManager.load_file()
    if not SaveManager.enabled() then return end
    SaveManager.token = SaveSystem.auto_load("data_file")
end

function SaveManager.save_file()
    if not SaveManager.enabled() then return end
    SaveManager.token = SaveSystem.auto_save("data_file", SaveManager.data)
end


function SaveManager.onProgress()
    if not SaveManager.enabled() then return end
--     if stingray.Keyboard.pressed(stingray.Keyboard.button_id("a")) then
--  	    SaveManager.data["level_1"]["stars"] = SaveManager.data["level_1"]["stars"]  + 1
--  	    SaveManager.save_file()
 	    
--  	end

    -- Save the file when invoked from other thread
    if (SaveManager.needToSave) then
        SaveManager.needToSave = false
        SaveManager.save_file()
        return
    end


    if (SaveManager.token) then
        local progress = SaveSystem.progress(SaveManager.token)

        if (progress and progress.done) then
            --print ("save - load done !")
    
            if (progress.error) then
                if (progress.error == "STINGRAY_SAVEDATA_ERROR_MISSING") then
                        -- File is missing - need to create new empty file and save it !
                        
                        SaveManager.create_empty_data()

                        SaveSystem.close(SaveManager.token)
                        SaveManager.token = nil
                        
                        SaveManager.save_file()
                        -- SaveManager.update_menu()
                        print ("save - load token closed")
                end
            else
                print ("File is Loaded OK...")

                -- Reading... only on loading
                if (progress.data) then
                    SaveManager.data = progress.data
                    -- SaveManager.update_menu()
                end
                
                print ("Stars "..SaveManager.get_stars_collected(1))

                SaveSystem.close(SaveManager.token)
                SaveManager.token = nil
                
            end
        end        
    end        
end

function SaveManager.shutdown()
    if not SaveManager.enabled() then return end

    if (SaveManager.token) then
        print ("Finallizing...")
        SaveSystem.close(SaveManager.token)
    end
end

function SaveManager.update_menu()
    if SimpleProject.level_name ~= "content/levels/Menu" or next(SaveManager.data) == nil then
        return false
    end
    
    local nora = stingray.World.unit_by_name(SimpleProject.world, "Character_Main2")
    if SaveManager.isFirst then
        stingray.Unit.flow_event(nora,"initPositionInMenu")
        SaveManager.isFirst = false
    else
        stingray.Unit.flow_event(nora,"positionInMenu")
    end
    
    for i = 1, 20 do
        local level_unit = stingray.World.unit_by_name(SimpleProject.world, "Level_" .. i)
        local locked = SaveManager.is_level_locked(i)
        local starCollected = SaveManager.is_star_collected(i)
        stingray.Unit.set_mesh_visibility(level_unit, "Lock", locked)
        stingray.Unit.set_mesh_visibility(level_unit, "Star_00", not locked)
        stingray.Unit.set_data(level_unit,"starCollected",starCollected)
        stingray.Unit.flow_event(level_unit,"updateStar");
        local stars = SaveManager.get_stars_collected(i)
        for j = 1, SaveManager.get_stars_collected(i) do
            stingray.Unit.set_mesh_visibility(level_unit, "Star_0" .. j, not locked)
        end
        for j = stars+1, 5 do
            stingray.Unit.set_mesh_visibility(level_unit, "Star_0" .. j, false)
        end
    end

    return true
end

-- level is the current level
function SaveManager.on_level_completed(level, numStars, hasBigStar)
    if (level  &amp;lt; 21) then
        SaveManager.data["Level_" .. level+1]["locked"] = false
    end    
    SaveManager.data["Level_" .. level]["stars"] = numStars
    SaveManager.data["Level_" .. level]["big_star_taken"] = hasBigStar
    SaveManager.needToSave = true
end

function SaveManager.get_max_levels_passed()
   if not SaveManager.enabled() then return 20 end

    for i = 1, 20 do
       if  (SaveManager.data["Level_"..i]["locked"] == true) then
           return i-1
        end 
    end
    
   return 20

end

return SaveManager&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Aug 2016 12:05:31 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/stingray-forum-read-only/savegame-data-implimentation/m-p/6493895#M5620</guid>
      <dc:creator>_robbs_</dc:creator>
      <dc:date>2016-08-11T12:05:31Z</dc:date>
    </item>
    <item>
      <title>Re: Savegame data implimentation</title>
      <link>https://forums.autodesk.com/t5/stingray-forum-read-only/savegame-data-implimentation/m-p/6494413#M5627</link>
      <description>&lt;P&gt;wow i can see how its all put together. if i were to use custom&amp;nbsp;flow nodes. can i use the variables similar to set_data() and get_data(). but instead of locating in global table it will look into the table of save game token. like for example set_data(weaponupgrade,mk51,4) and this varible be saved in the savegame table. then on retrieving the table from token i would use get_data(weoponupgrade,mk51,4) which will look into the table content of token instead of general&amp;nbsp;lua global table. and then passed that value to set_unit_data(). Am i write. i would timely need your help as i test this myself.Thanks for great help.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Aug 2016 14:52:18 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/stingray-forum-read-only/savegame-data-implimentation/m-p/6494413#M5627</guid>
      <dc:creator>Shanii2</dc:creator>
      <dc:date>2016-08-11T14:52:18Z</dc:date>
    </item>
    <item>
      <title>Re: Savegame data implimentation</title>
      <link>https://forums.autodesk.com/t5/stingray-forum-read-only/savegame-data-implimentation/m-p/6494668#M5630</link>
      <description>&lt;P&gt;Ah, one thing I forgot to mention in my last post is that after each auto_save or auto_load call is completed, you do need to call SaveSystem.close(token). This frees the memory used by your save/load request.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, after you call close(), you won't be able to read or write data to that token anymore. It's best to do like the code example, and persist the token.data by copying it to another variable in your project.&lt;/P&gt;</description>
      <pubDate>Thu, 11 Aug 2016 16:13:25 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/stingray-forum-read-only/savegame-data-implimentation/m-p/6494668#M5630</guid>
      <dc:creator>_robbs_</dc:creator>
      <dc:date>2016-08-11T16:13:25Z</dc:date>
    </item>
    <item>
      <title>Re: Savegame data implimentation</title>
      <link>https://forums.autodesk.com/t5/stingray-forum-read-only/savegame-data-implimentation/m-p/6494700#M5631</link>
      <description>&lt;P&gt;Yeah i grasp that so i need to call close token after i retrieved data or i should save the data table from token to a global table and then retrive data over time and pass the close call once the loading is completed&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Aug 2016 16:20:55 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/stingray-forum-read-only/savegame-data-implimentation/m-p/6494700#M5631</guid>
      <dc:creator>Shanii2</dc:creator>
      <dc:date>2016-08-11T16:20:55Z</dc:date>
    </item>
    <item>
      <title>Re: Savegame data implimentation</title>
      <link>https://forums.autodesk.com/t5/stingray-forum-read-only/savegame-data-implimentation/m-p/6494712#M5632</link>
      <description>&lt;P&gt;You can call close() anytime after the loading has completed, and after you have copied its token.data.&lt;/P&gt;
&lt;P&gt;Generally it's better to do this as soon as possible, since you won't need that token for anything after you've pulled out its data.&lt;/P&gt;</description>
      <pubDate>Thu, 11 Aug 2016 16:24:14 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/stingray-forum-read-only/savegame-data-implimentation/m-p/6494712#M5632</guid>
      <dc:creator>_robbs_</dc:creator>
      <dc:date>2016-08-11T16:24:14Z</dc:date>
    </item>
    <item>
      <title>Re: Savegame data implimentation</title>
      <link>https://forums.autodesk.com/t5/stingray-forum-read-only/savegame-data-implimentation/m-p/6494729#M5634</link>
      <description>&lt;P&gt;Thanks alot in this regard&lt;/P&gt;</description>
      <pubDate>Thu, 11 Aug 2016 16:28:56 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/stingray-forum-read-only/savegame-data-implimentation/m-p/6494729#M5634</guid>
      <dc:creator>Shanii2</dc:creator>
      <dc:date>2016-08-11T16:28:56Z</dc:date>
    </item>
  </channel>
</rss>

