Thread Tools Display Modes
04-07-10, 04:19 PM   #1
Zinc
A Deviate Faerie Dragon
Join Date: Mar 2010
Posts: 13
Creating a GUI, and saved variables?

Well, I was wondering two things.
1) How do I save variables between games? I don't know how to do it practically, because, I want to create an array and save strings in it, and I want it to keep it between games.

2) How can I create a GUI (In Lua)? I don't use or have any desire to learn how to use XML, and I want to put a button on the mini-map that will toggle a setting when pressed.
a) What are the natives for making a button on the mini-map?
b) What are the natives for creating a slash command?
  Reply With Quote
04-07-10, 04:48 PM   #2
Cralor
Mmm... cookies!!!
 
Cralor's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2007
Posts: 772
Creating a slash command: http://www.wowwiki.com/Creating_a_slash_command

Saved variables: http://www.wowwiki.com/Saving_variab..._game_sessions

As for minimap buttons, the best way is to probably look at how other addons do it. Probably a simple addon will be the easiest to read and understand.

Hope this helps.

P.S.: Google, WoWWiki, WoWProgramming, and many other sources are really helpful Don't forget about them!
__________________
Never be satisfied with satisfactory.
  Reply With Quote
04-07-10, 04:49 PM   #3
ravagernl
Proceritate Corporis
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 1,176
Originally Posted by Zinc View Post
Well, I was wondering two things.
1) How do I save variables between games? I don't know how to do it practically, because, I want to create an array and save strings in it, and I want it to keep it between games.

2) How can I create a GUI (In Lua)? I don't use or have any desire to learn how to use XML, and I want to put a button on the mini-map that will toggle a setting when pressed.
a) What are the natives for making a button on the mini-map?
b) What are the natives for creating a slash command?
1.) The SavedVariables field in the AddOns TOC. That you want to store it as a table is a good thing.

2.) Use something like LibDBIcon.

For your entire AddOn, you might like to try out the Ace framework. Note however, that it will probably be overkill.

http://www.wowace.com/addons/ace3/pa...tting-started/
http://www.wowace.com/addons/ace3/pages/

and AceGUI:
http://www.wowace.com/addons/ace3/pa...i/ace-gui-3-0/

Last edited by ravagernl : 04-07-10 at 04:50 PM. Reason: Drat, Cralor beat me to it!
  Reply With Quote
04-07-10, 04:50 PM   #4
Zinc
A Deviate Faerie Dragon
Join Date: Mar 2010
Posts: 13
Thanks for the quick reply, Man.

Anyways, I didn't really get those, but I`ll give them another read.
  Reply With Quote
04-07-10, 04:58 PM   #5
Waverian
A Chromatic Dragonspawn
AddOn Author - Click to view addons
Join Date: Dec 2006
Posts: 188
Originally Posted by Zinc View Post
1) How do I save variables between games? I don't know how to do it practically, because, I want to create an array and save strings in it, and I want it to keep it between games.


Use the SavedVariables metadata tag in your .toc file.

## Interface: 30300
<Other stuff>
## SavedVariables: MyAddOnDB

SavedVariables are just global variables that the client writes to a file on reload/exit. The value should be available after the ADDON_LOADED event fires.

Code:
-- Using the 3.3 convenience system to get the addon name
local ADDON_NAME, namespace = ...

local defaults = {
     SomeOption = true
     SomeOtherOption = 42
}

-- It's cleaner to use an event dispatcher here if you're going to use multiple events, but this is just a bare example
local function MyAddOn_OnEvent(self, event, name)
     -- this is executed if our addon has loaded
     if name = ADDON_NAME then
          -- use the existing sv table or create a new one if it doesnt exist (first load of the addon)
          MyAddOnDB = MyAddOnDB or {}
          for option, value in pairs(defaults) do
               -- populate our sv with default values if they don't exist (first load again)
               if not MyAddOnDB[option] then MyAddOnDB[option] = value end
          end
     end
end
Code:
2) How can I create a GUI (In Lua)? I don't use or have any desire to learn how to use XML, and I want to put a button on the mini-map that will toggle a setting when pressed.
GUIs in lua are made with CreateFrame widgets: http://wowprogramming.com/docs/widgets

You can see all of the functions each widget inherits that allow you to manipulate it at the wowprogramming documentation above.

I don't know how to create a minimap button offhand but you might find this code helpful (I also haven't actually looked at it myself): http://www.wowinterface.com/download...onoptions.html


b) What are the natives for creating a slash command?
All values in the SlashCmdList table are automatically handled to create a slash command.

Code:
SlashCmdList['MYADDONSLASH'] = function()
     print('Hello world')
end
-- Format is SLASH_<VAL>N where <VAL> is the name of the key in the SlashCmdList table and N is any number.
SLASH_MYADDONSLASH1 = '/hello'
SLASH_MYADDONSLASH2 = '/hw'
You can use pattern matching to interpret multiple user commands in your slash command handler, example here: http://www.wowwiki.com/Creating_a_slash_command
  Reply With Quote
04-07-10, 05:04 PM   #6
Zinc
A Deviate Faerie Dragon
Join Date: Mar 2010
Posts: 13
The most confusing thing for the slash commands is there are never nice examples.

Could you do an example for the command '/quizzer' and have it print a message? That'd be easier to read
  Reply With Quote
04-07-10, 05:10 PM   #7
Waverian
A Chromatic Dragonspawn
AddOn Author - Click to view addons
Join Date: Dec 2006
Posts: 188
My previous example seems pretty "nice."

Code:
SlashCmdList['QUIZZER'] = function()
     print('Quizzer: A message!')
end
SLASH_QUIZZER1 = '/quizzer'
  Reply With Quote
04-07-10, 05:18 PM   #8
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,954
Originally Posted by Zinc View Post
The most confusing thing for the slash commands is there are never nice examples.

Could you do an example for the command '/quizzer' and have it print a message? That'd be easier to read
Here's what I do...

Code:
-- Set up the Slash Commands 
SLASH_<NameOfAddon>Cmd1 = '/swf';
SlashCmdList['<NameOfAddon>Cmd'] = FunctionToValidateSlashCommands;

function FunctionToValidateSlashCommands(msg)
   local origmsg = msg;    -- I always do this in case I need the case sensitive parts such as text to display.
   msg = string.lower(msg);  -- Convert to lower case for testing purposes
   -- Now create a table to separate the msg into components
   local args = {};
   for word in string.gmatch(msg,"[^%s]+") do
      table.insert(args,word);
   end
   -- Now validate the commands and act appropriately
   if ( args[1] == "cmd" ) then
      if ( args[2] ) then
         print("Message ", msg, " contained the command ", cmd, " with an additional value of ", args[2]);
     else
         print("Message ", msg, " contained the command ", cmd, " with no additional values);
     end
  end
end
These would work so that you would type something like
/addonName cmd value
And then deal with each element as you tell it to.
__________________


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
04-07-10, 07:14 PM   #9
Zinc
A Deviate Faerie Dragon
Join Date: Mar 2010
Posts: 13
Woah, thanks guys, this is all so helpful!
  Reply With Quote
04-07-10, 08:14 PM   #10
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,954
Rofl, of course it would work better if you replace cmd in the print statement with args[1] rofl .. just noticed that part.
__________________


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

WoWInterface » Developer Discussions » General Authoring Discussion » Creating a GUI, and saved variables?


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