Thread Tools Display Modes
07-07-10, 02:51 PM   #21
b3vad
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Jun 2010
Posts: 21
variables ?

I'm back with more questions (and tnx for answers ChaosInc)
-------------
1- to save my settings i need some variables but i cant manage to make variables that addon save and load with
Code:
## SavedVariablesPerCharacter: K1OB_var
and
Code:
K1OB_var = {
["K1OB_FixMe_V"]= false;
}
(is it something like array?)
and i cant find any data in wowwwiki about variables and array and best way to change save and load them
any tip and or guide can be a big help for me

2- how bout saving/loading a list ? (I'm trying to add a list that player can add items to delete when loot) any idea how i can do it very simple?
  Reply With Quote
07-07-10, 04:33 PM   #22
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,928
You're doing okay there but perhaps it is how you are using it in your addon.


The TOC is correct.

Assuming the code segment is in your code at the top of the lua file then that is correct to, oh wait not quite. The question is how are you accessing it or updating it ?

EG.
K1OB_var = {
["K1OB_FixMe_V"]= false,
... Other default values or settings
}

K10B_var["K10B_FixMe_V"] = true;

if ( K10B_var["K10B_FixMe_V"] ) then
--Lets say you want to add something to a list here, lets use the current list
--or if there isn't one yet create one.
K10B_var["K10B_FixMe_L"] = K10B_var["K10B_FixMe_L"] or {}
--Now we can use it to if we wish, like insert a value to the end of the list
tinsert(K10B_var["K10B_FixMe_L"],"somerandomvalue")
etc
end

--If you want to give the user an option to reset the data at any time then
--do something like this. You can then add in your chosen default values.
function ResetData()
K10B_var = {}
end

Your saved variables data will be restored when the ADDON_LOADED event is triggered for your addon so inside your functions used during game play your data is available by default. Any changes made during play time will be written back during the PLAYER_LOGOUT event. All you need to do is set the values as and when you need. Setting the default values outside of functions will mean you will always have a functional set of data in the case of this being a first use session or the Saved Variable file has been deleted.
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818
  Reply With Quote
07-13-10, 05:03 AM   #23
b3vad
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Jun 2010
Posts: 21
still cant get the whole var loading thing

i still don't get it . if i have
Code:
K1OB_var = {
["K1OB_FixMe_V"]= false;
}
as my first lines of my .lua does it makes my var set to "false" every time i load my addon? or i have some other mistake in loading and saving this var because it don't work .
addon is attached
-------------------
and ty Xrystal for answers its really big help
Attached Files
File Type: zip K1OptionBox.zip (2.9 KB, 795 views)

Last edited by b3vad : 07-13-10 at 05:12 AM. Reason: Addon is now attached
  Reply With Quote
07-13-10, 05:30 AM   #24
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,928
If you never change the value then yes it will always be false. If you change it before the user shuts down it should update the WTF file for that addon.

Edit: Looked at the code ..

Change the toc so that the lua file is above the xml file. The xml file is trying to access functions that don't exist yet.

Apart from that I can't see anything wrong.
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818

Last edited by Xrystal : 07-13-10 at 05:37 AM.
  Reply With Quote
07-13-10, 06:26 AM   #25
b3vad
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Jun 2010
Posts: 21
the problem

i think the problem is my 3 first line of .lua
Code:
K1OB_var = {
["K1OB_FixMe_V"]= false;
}

function K1OB_Register()
K1OB_SetBoxes();
this:RegisterEvent("MERCHANT_SHOW");
this:RegisterEvent("PLAYER_MONEY");
this:RegisterEvent("RESURRECT_REQUEST");
this:RegisterEvent("PLAYER_DEAD");
this:RegisterEvent("PARTY_INVITE_REQUEST");
this:RegisterEvent("DUEL_REQUESTED");
this:RegisterEvent("GUILD_INVITE_REQUEST");
this:RegisterEvent("ARENA_TEAM_INVITE_REQUEST");
this:RegisterEvent("PETITION_SHOW");

K1OB_Money();
end

function K1OB_SetBoxes()
if K1OB_var["K1OB_FixMe_V"] then
	K1OB_FixMe:SetChecked();
else
	K1OB_FixMe:SetChecked(false);
end
end



function K1OB_EventHandeler()
if (event == "MERCHANT_SHOW") then
K1OB_Merchant();
end
if (event == "PLAYER_MONEY") then
K1OB_Money();
end
if (event == "RESURRECT_REQUEST") then
K1OB_Ress();
end
if (event == "PLAYER_DEAD") then
K1OB_Release();
end
if (event == "PARTY_INVITE_REQUEST") then
K1OB_Party();
end
if (event == "DUEL_REQUESTED") then
K1OB_Duel();
end
if (event == "GUILD_INVITE_REQUEST") then
K1OB_Guild();
end
if (event == "ARENA_TEAM_INVITE_REQUEST") then
K1OB_Arena();
end
if (event == "PETITION_SHOW") then
K1OB_ArenaCharter();
end
if (event == "PETITION_SHOW") then
K1OB_Petition();
end
end

--CheckBoxes
function K1OB_Merchant()
isChecked = K1OB_FixMe:GetChecked();
canRepair = CanMerchantRepair();
AllChecked = K1OB_O1:GetChecked();
if (canRepair == 1)then
if (isChecked == 1 or AllChecked == 1) then
RepairAllItems();
end
end
end

function K1OB_Petition()
petitionType = GetPetitionInfo()
if (petitionType == guild) then
isChecked = K1OB_GuildCharter_C:GetChecked();
AllChecked = K1OB_O1:GetChecked();
if (isChecked == 1 or AllChecked == 1) then
SignPetition();
end
else
isChecked = K1OB_ArenaCharter_C:GetChecked();
AllChecked = K1OB_O1:GetChecked();
if (isChecked == 1 or AllChecked == 1) then
SignPetition();
end
end
end

function K1OB_Ress()
isChecked = K1OB_O4:GetChecked();
AllChecked = K1OB_O1:GetChecked();
if (isChecked == 1 or AllChecked == 1) then
AcceptResurrect();
end
end

function K1OB_Release()
isChecked = K1OB_Release_C:GetChecked();
AllChecked = K1OB_O1:GetChecked();
if (isChecked == 1 or AllChecked == 1) then
RepopMe()
end
end

function K1OB_Party()
isChecked = K1OB_O2:GetChecked();
AllChecked = K1OB_O1:GetChecked();
if (isChecked == 1 or AllChecked == 1) then
AcceptGroup();
end
end

function K1OB_Duel()
isChecked = K1OB_O3:GetChecked();
AllChecked = K1OB_O1:GetChecked();
if (isChecked == 1 or AllChecked == 1) then
AcceptDuel();
end
end

function K1OB_Guild()
isChecked = K1OB_GuildInvite_C:GetChecked();
AllChecked = K1OB_O1:GetChecked();
if (isChecked == 1 or AllChecked == 1) then
AcceptGuild();
end
end

function K1OB_Arena()
isChecked = K1OB_ArenaTeam_C:GetChecked();
AllChecked = K1OB_O1:GetChecked();
if (isChecked == 1 or AllChecked == 1) then
AcceptArenaTeam();
end
end

function K1OB_Summon()
isChecked = K1OB_Summon_C:GetChecked();
AllChecked = K1OB_O1:GetChecked();
if (isChecked == 1 or AllChecked == 1) then
ConfirmSummon();
end
end

--Other
function K1OB_Money()
money = GetMoney();
K1OB_Gold:SetText(GetCoinTextureString(money," "));
end

function K1OB_Main_Show()
if K1OB_OptionFrame:IsShown() then
K1OB_OptionFrame:Hide();
else
K1OB_OptionFrame:Show();
end
end

function K1OB_DeleteItem()
	hasItem = CursorHasItem();
	if (hasItem) then
		DEFAULT_CHAT_FRAME:AddMessage("Deleting Item");
		DeleteCursorItem();
	end
end

function K1OB_FixMe_OnClick()
isChecked = K1OB_FixMe:GetChecked();
if (isChecked == 1) then
K1OB_var["K1OB_FixMe_V"] = true;
		DEFAULT_CHAT_FRAME:AddMessage("True");
else
K1OB_var["K1OB_FixMe_V"] = false;
		DEFAULT_CHAT_FRAME:AddMessage("False");
end
end
yellow parts are codes for create/use/save my variable but it seems every time variable loads create part set it to "false"
i will try to move the create part somewhere else to see if it makes any different
Note : i checked my var is saved = True on disk so problem is after load
----------------
i wonder how to create empty var ?

Last edited by b3vad : 07-13-10 at 06:28 AM.
  Reply With Quote
07-13-10, 12:46 PM   #26
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,928
Hmm, change the ';' in that first block of code to ','. It may be stopping it from setting the table properly but from the sounds of it maybe not.


Now for some true programming testing.

1. Delete the Saved Variables wtf file for that addon.
2. Log in and note what the settings are set to.
3. Change some of the values you want changing and note them.
4. Log Out and look at the Saved Variables file and note the values ( copy the file possibly - which I do sometimes )
5. Log In and note what the settings are set to.
------- At this point when you log in they should reflect what the wtf file is
------- storing. If not you are not using the values in the right place
6. Change some more values ( different ones ) and note them.
7. Log Out and look at the Saved Variables file and note the values ( copy again if you want so you can compare the files later )
8. You can then repeat steps 5 to 7 with different settings. If you have the code set up right you should see the changes happening on log and the settings stored on log out.


From the sounds of it though the wtf file is being set but the true value is not being set on the check box. That could be due to this line:
K1OB_FixMe:SetChecked();
Try changing that to
K1OB_FixMe:SetChecked(true);
And see if that resolves your problem. A nil value is generally counted as false so possibly could be ignoring your setting.
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818
  Reply With Quote
07-14-10, 08:12 AM   #27
b3vad
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Jun 2010
Posts: 21
still not working

i tested every line of code every thing works perfect accept
Code:
K1OB_var = {
["K1OB_FixMe_V"]= {};
}
if i don't use this code I'll get lua error . and when i use it . it sets my var to its value each time addon is loaded .
i wonder how do you save your addon's settings? can you give me a very simple example code ?
  Reply With Quote
07-14-10, 09:50 AM   #28
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,928
Okay, found a simple example of mine.

In TOC I have nUI_ABGDData located in SavedVariables line
Code:
## SavedVariables: nUI_ABGDData
As a new standard since they implemented it I have the following line at the top of all my addon's LUA files just in case I need global access to shared data. This allows me to split the addon into multiple files which can then be used in multiple addons but still be unique to each addon data wise. For small addons that only use 1 LUA file this shouldn't need to be here but it's a nice easy way to store the addon's name in a variable
Code:
local addonName,addonData = ...
In LUA I have the following near the top of the file. It is similar to your line except I have split the table setup onto 2 lines. This would be the same as writing nUI_ABGDData = { GridDisplay = "auto", } or nUI_ABGDData = { ["GridDisplay"] = "auto", } etc
Code:
--[[ Initialise Saved Variable Table with Default Values ]]--
nUI_ABGDData = {};
nUI_ABGDData.GridDisplay = "auto";
I then have the following set of functions ( which I have changed to only reflect the parts of the code you would need - naming apart )
Code:
--[[ Make changes based on SavedVariables settings ]]--
local function UseSavedVariables(savedVarValue)
    if ( savedVarValue == "on" ) then 
      -- Other settings and actions here
      nUI_ABGDData.GridDisplay = "on"
    elseif ( savedVarValue == "off" ) then
      -- Other settings and actions here
      nUI_ABGDData.GridDisplay = "off"
    elseif ( savedVarValue == "auto" ) then
      -- Other settings and actions here
      nUI_ABGDData.GridDisplay = "auto"
    end			
  end
end
And these are the functions I pretty much use near the end of my LUA file that are adjusted to suit the individual addon's requirements but is pretty much the basis of all my addons in some form or another.
Code:
--[[ Check the slash commands ]]--
local function SlashCommands(msg)

  -- store both an original version of the message string 
  -- as well as a lower case version for testing purposes
  local origMsg = msg
  local lowerMsg = string.lower(msg)

  -- convert to lower case and break up arguments
  local slashArgs = {};
  for word in string.gmatch(lowerMsg,"[^%s]+") do
    table.insert(slashArgs,word)
  end

  -- Set the grid display based on arguments
  if ( slashArgs[1] ) then
    UseSavedVariables(slashArgs[1]);
  else
    -- Maybe the users need to know what options are available
  end

end

-- Blizzard has finished loading their variables so we can override any changes they may have done to our settings
local function LoadVariables(self,event,...)
  -- Set the grid display according to saved variables
  UseSavedVariables(nUI_ABGDData.GridDisplay);
  -- No need to come here again
  self:UnregisterEvent(event);
end

--[[ Our addon variables are loaded so we can do some stuff ]]--
local function AddonLoaded(self,event,...)
  -- If not our addon then go away
  if ( arg1 ~= addonName ) then return end
  -- Set Up the Slash Command Handler
  SLASH_MyAddonCmd1 = '/myaddon';
  SlashCmdList['MyAddonCmd'] = SlashCommands;

  -- Don't need to come back here
  self:UnregisterEvent(event)
end

--[[ Handle the OnEvent for the event frame ]]--
local function OnEvent(self,event,...)	
  if ( event == "VARIABLES_LOADED" ) then 
    LoadVariables(self,event,...)
  elseif ( event == "ADDON_LOADED" ) then
    AddonLoaded(self,event,...)
  end
end

--[[ Create the Event Frame and Assign its events to watch ]]--
local EventFrame = CreateFrame("Frame","myUniqueEventFrameName",UIParent);
EventFrame:RegisterEvent("VARIABLES_LOADED");
EventFrame:RegisterEvent("ADDON_LOADED");
EventFrame:SetScript("OnEvent",OnEvent);
Hopefully that is enough for you to get your head around things.
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818
  Reply With Quote
07-21-10, 03:01 PM   #29
b3vad
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Jun 2010
Posts: 21
thatnk you for great answer

well i finally managed to solve the problem with making several variables and saving them but i needed to learn the standard way too will use it next time ty.

lets not waste a post and ask another question :

i registered
Code:
this:RegisterEvent("TRADE_ACCEPT_UPDATE");
then my event handler
Code:
if (event == "TRADE_ACCEPT_UPDATE") then
K1OB_Trade();
end
and finally my function
Code:
function K1OB_Trade()
isChecked = K1OB_Trade_C:GetChecked();
AllChecked = K1OB_All:GetChecked();
if (isChecked == 1 or AllChecked == 1) then
AcceptTrade();
end
end
just like any other option i added in my addon but it seems have args and i don't know where to put them do you know where? ty again
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » need help to learn and compleet my simple addon

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off