LoTROInterface

LoTROInterface (https://www.lotrointerface.com/forums/index.php)
-   Lua Programming Help (L) (https://www.lotrointerface.com/forums/forumdisplay.php?f=50)
-   -   Saving and loading help (https://www.lotrointerface.com/forums/showthread.php?t=1679)

Queekusme 11-12-2011 10:25 AM

Saving and loading help
 
Hiya,

For Kmabc 1.2 i am implementing saving and loading. But however, i am at a standstill:(. I am trying to save quickslot data to the plugindata but cannot get anywhere. the code so far is:
Code:

local savedatax ={
                quickslot1SavData = "",
                quickslot2SavData = "",
                quickslot3SavData = "",
                quickslot4SavData = "",
                quickslot5SavData = "",
                quickslot6SavData = "",
                quickslot7SavData = "",
                quickslot8SavData = "",
                quickslot9SavData = "",
                }

and
Code:

Save.Click = function( sender , args )

                        savedatax.quickslot1SavData = quickslot1:GetShortcut();
                        savedatax.quickslot2SavData = quickslot2:GetShortcut();
                        savedatax.quickslot3SavData = quickslot3:GetShortcut();
                        savedatax.quickslot4SavData = quickslot4:GetShortcut();
                        savedatax.quickslot5SavData = quickslot5:GetShortcut();
                        savedatax.quickslot6SavData = quickslot6:GetShortcut();
                        savedatax.quickslot7SavData = quickslot7:GetShortcut();
                        savedatax.quickslot8SavData = quickslot8:GetShortcut();
                        savedatax.quickslot9SavData = quickslot9:GetShortcut();

                        Turbine.Shell.WriteLine("Pre Save");

                        Turbine.PluginData.Save(Turbine.DataScope.Character, "KmabcSaveData", savedatax); --

                        Turbine.Shell.WriteLine("Post Save");
                end

can anyone point me in the right direction please

thanks Queekusme

PS. i get the file with the names in but no value to put into them.

PPS. i know how to put plain text into the savedata file but not quickslot data so i request that people dont tell me this.

Cearbhall 11-12-2011 11:20 AM

the reason that is not working is because :GetShortcut() returns the class Turbine.UI.Lotro.Shortcut
which isn't the data you want

this is what i do
Code:

quickslot.ShortcutChanged = function(sender, args)
        local shortcut = sender:GetShortcut()
        local type, data = shortcut:GetType(), shortcut:GetData()
        if type == Turbine.UI.Lotro.ShortcutType.Undef then
                DB.quickslots[sender._index] = nil
        else
                DB.quickslots[sender._index] = {type, data}
        end
end

--and to load the data

if DB.quickslots[quickslot._index] then
        quickslot:SetShortcut(Turbine.UI.Lotro.Shortcut(DB.quickslots[quickslot._index][1], DB.quickslots[quickslot._index][2]))
end


--quickslot._index is something i set to show what slot it represented


Queekusme 11-12-2011 02:12 PM

I dont really understand this, what i want to do is save the data to the file so that it puts a hexcode there... how can i use this to make it do that?

MrJackdaw 11-12-2011 04:54 PM

Quote:

local type, data = shortcut:GetType(), shortcut:GetData()
Is the important part here and the data you need - this is the hex code for the skill and the type of skill. These are also what you use when you set a skill.

Do you use a bar plugin at all? If you do you should be able to extract the codes you need from its save data.

Alternatively

Quote:

shortcut= quickslot:GetShortcut()
type, data = shortcut:GetType(), shortcut:GetData()
Will get you the data you need from one quickslot that you build. Obviously, save etc as you wish!

Queekusme 11-13-2011 06:04 AM

So how do i put that in the context of my code is it something like

Code:


local savedatax ={

        shortcut = quickslot1:GetShortcut()
        local type, data = shortcut:GetType(), shortcut:GetData()
                                   
        quickslot1SavData = type,data,
                  -- And then copy for the other shortcuts...
                }

and to load it (copied from Cearbhall)

Code:

quickslot1:SetShortcut(Turbine.UI.Lotro.Shortcut(type value,data value)) -- type and data values called from the loadup process

Garan 11-13-2011 09:43 AM

Quote:

Originally Posted by Queekusme (Post 7368)
Code:

quickslot1:SetShortcut(Turbine.UI.Lotro.Shortcut(type value,data value)) -- type and data values called from the loadup process

If there is any chance that your saved quickslot data could have an Alias type shortcut, you can run into a Turbine bug using the default Shortcut constructor with international characters. To avoid that issue with german and french users, use the :SetData() method to set the shortcut like:
Code:

local sc=Turbine.UI.Lotro.Shortcut();
sc:SetType(typeValue);
sc:SetData(dataValue); -- works with international characters
Quickslot1:SetShortcut(sc);

It's not as pretty but it avoids the international character bug in the constructor. You should also be using some form of encoding for your save data and load data routines (I use Vindar's patch available here on LoTROInterface.com)

Queekusme 11-13-2011 01:42 PM

Thanks for the help, i'll try this tomorrow, and i'll look into vindir....'s patch as encoding allways helps

thanks again

Queekusme

EDIT: thanks again for this but i never intended for there to be alias strings to be saved anyway, but thanks as this will prevent people complaining :)

Equendil 11-13-2011 08:30 PM

Quote:

Originally Posted by Queekusme (Post 7368)
So how do i put that in the context of my code is it something like

Code:


local savedatax ={

        shortcut = quickslot1:GetShortcut()
        local type, data = shortcut:GetType(), shortcut:GetData()
                                   
        quickslot1SavData = type,data,
                  -- And then copy for the other shortcuts...
                }


That wouldn't work.

If you write "a,b = x,y" a is set to the value of x and b is set the value of y. If you write "a =x,y" a is set to the value of x and y is discarded.

In your case, 'quickslot1SavData' would be set to the value of 'type' and 'data' would be discarded.

You could however, make your quickslotxSavData tables then set both type & data:

Code:

quickslot1SavData = {}
quickslot2SavData = {}
...

Code:

(...)
quickslot1SavData.type, quickslot1SavData.data = type, data
(...)


Queekusme 11-14-2011 11:08 AM

So what you're saying is that i should save each piece seperately insted of in the same piece of information string.

i see where you are getting at, ok, i'll try this after my tea and homework tonight

Equendil 11-14-2011 04:07 PM

Quote:

Originally Posted by Queekusme (Post 7372)
So what you're saying is that i should save each piece seperately insted of in the same piece of information string.

Well, you *can't* set one variable to two values.

If you write "quickslot1SavData = type,data", what the lua runtime does is "quickslot1SavData = type", and then it discards 'data'.

See Lua Reference Manual

Quote:

Before the assignment, the list of values is adjusted to the length of the list of variables. If there are more values than needed, the excess values are thrown away. If there are fewer values than needed, the list is extended with as many nil's as needed.


All times are GMT -5. The time now is 02:46 AM.

vBulletin® - Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
© MMOUI