WoWInterface

WoWInterface (http://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (http://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Question on "First Use" (http://www.wowinterface.com/forums/showthread.php?t=821)

diiverr 06-01-05 07:35 AM

Question on "First Use"
 
Before I start digging around in other mods, I thought I'd toss this out there for anyone that might be bored. Please note, anyone who may respond, that I could -barely- get a chat message to fire <OnLoad>. The notion of saved variables makes me blanch to say the very least. Short version, lua > me. :)

What I would like to do is register DiivSkins such that it will call a function that will call another function from another AddOn (I think?) the first time someone loads my AddOn. (on any character, not character specific) Once that happens, I don't want that function to ever be called again.

I also need the XML call for it to be universal, that is, I just want to paste one <OnLoad> into several frames, and then... use a "( this )" ... I think? I'm not sure.

If anyone out there is at all familiar with DiivsSkins, basically, what this would do is call a MoveAnything! function to default check [Hide] on the "non standard" frames that paste all over the screen on initial start-up. (The ones I use that employ the "UIParent" as a Parent). These frames would then be invisible as "hidden" the first time a player logs into game. After that, I don't want to call that function again, however, or the user would have to go back into the MoveAnything! console before each session and un-check all the "hidden" elements they had previously "un-hid" for their UI set up. No good.

I'll do more homework on this later, I promise. I do know the MoveAnything function I need to call, I just don't know how to properly implement it in DiivSkins to accomplish what I'm after.

I'm headed out the door for work at the moment. I just thought I would toss this out there, as I said, in case anyone is bored enough to patronize the clueless. ;).

Kaelten 06-01-05 07:41 AM

Well.. part of the problem that may arise is that many addons need all character data to fire before off and become available before a addon can really use them. So what may work for you is to put a function call in your on update block that looks something like this.

hasran = false;

function diiv_onupdate()
if(not hasran) then
--I'd recommending checking that MoveAnything is installed, and if it is not
--then hide the frame by another method.
Call function here!
hasran = true;
end
end

Gello 06-01-05 08:15 AM

SavedVariables is really simple. In the .toc, add this line:

## SavedVariables: myvariable

That's all there is to it. The value of myvariable will persist across sessions. How it works is pretty neat:

1. When you log in, each mod's lua gets "run" once.
specifically: from the <Script file="mymod.lua"/> line, WoW runs this file. It doesn't execute functions, but it picks up all version=1.0, stuff=etc that you define outside of functions
2. After the loading chugs a bit, the game "runs" the SavedVariables.lua file.
specifically: open SavedVariables.lua and you'll see a bunch of variable declarations. WoW doesn't "interpret" this file, it just runs it. While logged out, you could edit the file to add your own code and it'd run when you log back in.
3. When the game closes, it deletes SavedVariables.lua, then goes through all addons' .toc files to recreate it.
specifically: It goes through every .toc and if it sees ## SavedVariables (something), then it adds (something) into SavedVariables.lua in a form that can be run the next time a character logs in.

This is why your mod can say:
--MyMod.lua--
Code:

x=100

function MyMod_OnUpdate()
    --etc
end

functon MyMod_OnEvent()
    --etc
end

Then in game you do /script x=900. Then the next time you run it will stay 900 despite clearly saying x=100. It runs MyMod.lua and makes x=100. Later, it runs SavedVariables.lua. If there's an x=900 there, x will now be 900.

That's all you need to know, except to remember that SavedVariables.lua is always run just before the VARIABLES_LOADED event. So if you ever want to act on a saved variable at startup, make sure to put it there:

--MyMod.lua--
Code:

x=100

function MyMod_OnUpdate()
    this:RegisterEvent("VARIABLES_LOADED");
end

functon MyMod_OnEvent()
    if event=="VARIABLES_LOADED" then
      x = whatever x was when the user last logged out
    end
end

So to tweak the above a bit:

Code:

DS_UsedBefore = false

function DS_OnLoad()
    this:RegisterEvent("VARIABLES_LOADED")
end

function DS_OnEvent()
    if event=="VARIABLES_LOADED" then
        if not DS_UsedBefore then
            -- do one-time stuff for first use
            DS_UsedBefore = true
        end
    end
end


diiverr 06-02-05 01:14 PM

Cleaned all my junk posts out of this thread. ;)


Using the above advice, a future DiivSkins will be much more "friendly" to the first time user. Thank you much for your help folks.

If you are lurking and curious how this all worked out, here's the code.

Lua snip:
Code:

function DS_OnEvent()
        if event=="VARIABLES_LOADED" then
                if not DS_UsedBefore then
                        -- do one-time stuff for first use here

                        -- display the primary game menu without a keypress
                        GameMenuFrame:Show();
                        -- display an attatched text frame to this menu
                        DS_Init:Show();

                        -- hide all the DiivSkin crud normally visible at start up
                        DS_Hbar1:Hide();
                        DS_Hbar2:Hide();
                        DS_Hbar3:Hide();
                        DS_Hbar4:Hide();
                        DS_Hbar5:Hide();
                        DS_Hbar6:Hide();
                        DS_Hbar7:Hide();
                        DS_Hbar8:Hide();
                        DS_Vbar1:Hide();
                        DS_Vbar2:Hide();
                        DS_Vbar3:Hide();
                        DS_Vbar4:Hide();
                        DS_leftendcap:Hide();
                        DS_rightendcap:Hide();
                        DS_leftendcap_2:Hide();
                        DS_rightendcap_2:Hide();
                        DS_smallcorner_R:Hide();
                        DS_smallcorner_L:Hide();
                        DS_link_1:Hide();
                        DS_link_2:Hide();

                        --register the variable as true, so the above never happens again.
                        DS_UsedBefore = true
                end
        end
end

Now, instead of THIS , we get THIS . :)

If you are following along at home, the above is referenced in my XML by this code here:
Code:

                        <Scripts>
                                <OnLoad>
                                        DS_OnLoad();
                                        DS_Init:Hide();
                                </OnLoad>
                                <OnEvent>
                                        DS_OnEvent();
                                </OnEvent>
                        </Scripts>

What that does is call the two functions above, and also hide the text frame by default, so it doesn't display every time you access the game menu. Thanks to the "first use" code above, This all will only happen once. Aftere a relog, or a ReloadUI, we're back to business as usual.

Gello, Kaelten, Thanks again the help. :)


All times are GMT -6. The time now is 11:21 PM.

vBulletin © 2014, Jelsoft Enterprises Ltd
©2012 ZAM Network LLC