• 0

    posted a message on making variables from strings
    i thought i'd post my finished line of code here for research purposes for anyone else that might be a bit confounded as i was.

    in Levelwiz_revamped.lua:

            elseif (event == "CHAT_MSG_COMBAT_XP_GAIN") then
        local _,_,_,killEXP,_ = string.find(a1, LWR_STR_COMBATXPNOTE)
        if killEXP then LWR_prevXPkill = tonumber(killEXP) end
        if LWR_prevXPkill < 0 then LWR_prevXPkill = 0 end
     end
    


    in my localization.lua

    LWR_STR_COMBATXPNOTE    = "(.*) dies, you gain (%d+) experience."
    


    it may very well be possible that i have more then one _ in the beginning of my call handler but after a lot of testing this is the string that worked for what i was needing called.

    credit goes to the author of titanpanel XP of whom i got the idea that it was possible to seperate xp gains from kill gains and based the majority of the code off of.

    thanks again for all your guys help! with this line completed i can officially call my addon ready!:D (even if it is just a rehash :P )
    Posted in: Lua Code Discussion
  • 0

    posted a message on making variables from strings
    understood... thanks for the info guys! :)
    Posted in: Lua Code Discussion
  • 0

    posted a message on making variables from strings
    ahh i see... another thing that is puzzling me that i was looking up in the lua refrence manual and i cant seem to find... what is _, ? is that like ome unused variable?
    Posted in: Lua Code Discussion
  • 0

    posted a message on making variables from strings
    just out of curiosity, is it possible to pull a number out of a string and use the number value in math? i tried like in the following but i never get an exact number, just a lower number

    X = string.find("some number of 45", "%d+")


    but when i call that it doesnt return the number 45 it returns something less which makes it no good for use in math if i need the number in question to be pulled
    Posted in: Lua Code Discussion
  • 0

    posted a message on making variables from strings
    thanks for the help guys, i switched the LevelTime call to just = a2 then made a secondary call in the function to convert to SecondsToTime() to get a time format. i also found a way to add more lines into it for a more precise look :)

    i guess i shouldof figured SecondsToTime() was a string lol :P
    Posted in: Lua Code Discussion
  • 0

    posted a message on making variables from strings
    hey all,

    sorry to bug again but i cant seem to get the addon i'm working on to register that my variables should be numbers. not strings. but for some reason when i load the addon it loads with an error saying it cant do the arithmetic for string value. when i looked over all the code i diddnt find any links to strings so i might just not be typing it up right i dunno :/

    function LvlWizRev_EstXpTime()
    local lvltime = LevelTime
    local UXP=UnitXP("PLAYER")
    ET = UXP / lvltime * 3600
    print (ET)
    --if ET==0 then ET="inf."end
    --LvlWizRev_Tooltip:AddLine("|cFF6495EDEstimated time to level up: "..ET.."|r")
    
    end
    


    this is the function i'm having issues with and it tells me that lvltime is the problem "string"

        elseif (event == "TIME_PLAYED_MSG") then
              -- Remember play time
              AllTime = SecondsToTime(a1);
           LevelTime = SecondsToTime(a2); 
    


    is what's in my Onevent function that grabs the initial data

    and these are my session variables(note some of them actually dont do anything i need to clean these up lol):

    local LevelTime =0
    local lvltime = 0
    local LWR_currXP = 0
    local LWR_exptogo = 0
    local LWR_Init = nil
    local WML = 0
    local NUMMOBS = 0
    local TPL = 0
    local TX = 0; --(total amount of xp needed to level)--
    local UXP = 0; --(current amount of xp aquired)--
    local PT = 0 --(current amount of played time)--
    local lxp = {} --(current player XP)--
    local mkc=0  --(kills needed on specific mob to level up)--
    local lastkillXP=0 --(last kill xp reward)--
    local TL= {} --(level of the current target selected)--
    local LWR_prevXP=0
    PLT = 0
    local prev_update = 0
    local prev_update_delay = 4
    local LvlWizRev_Update_Freq = 1
    



    then finally it all is supposed to wrap in nice and neatly into my LvlWizRev_ShowTooltip() function which works for everything else. i've been over this bit of code trying to tweak and change it but i usually end up with a string error or cant do an upvalue on nil, so i'm lost lol any help is greatly appreciated! :)
    Posted in: Lua Code Discussion
  • 0

    posted a message on Where Do I Start?
    there's a good ingame lua interpretyer called WowLua i use it occasionally to test out functions and the like. it's pretty handy for catching typos and missed ends and things before loading into the main game. i also set up a global macro for ease of use to reload the user interface.

    /console reloadui

    that should help some :)
    Posted in: Lua Code Discussion
  • 0

    posted a message on looking for refrence code
    wow i feel totally dumb lol, on an appifiny (sp?) i tried the SecondsToTime() call on the OnEvent handler for the TIME_PLAYED_MSG to make it look like so:

       elseif (event == "TIME_PLAYED_MSG") then
              -- Remember play time
              AllTime = SecondsToTime(a1);
           LevelTime = SecondsToTime(a2);
    

    and it worked! rofl guess i was overthinking the situation! :P anyways it looks like i want it to with that. thanks for helping me find what i was looking for still though LaoTseu :)
    Posted in: Lua Code Discussion
  • 0

    posted a message on looking for refrence code
    yeah that should work, i'll see if i can play around with this and get my addon to use this correctly, thanks a lot! :)

    edit: i took a look at the addon you suggested, and it actually looks like it might help me figure out another issue i've been having with saving the levelup timestamp lol
    Posted in: Lua Code Discussion
  • 0

    posted a message on looking for refrence code
    lol allright, fair enough :P

    basically i am trying to get my addon to report all the info that you recieve when doing /played (time on current level and total time played on said alt) and it reports it, but only gives it back into seconds value :/ so what i'm trying to do is find a way to make it tell me the seconds, minutes, hours and days(all if applicable of course) rather then say 60000000000 seconds lol
    i'll paste my codes below i used for refrence



    elseif (event == "TIME_PLAYED_MSG") then
              -- Remember play time
              AllTime = a1;
           LevelTime = a2;
    
    
    

    this is in the OnEvent function

    function LvlWizRev_ShowTooltip()
    LvlWizRev_TextCalc()
    CLT = LevelTime --time on current level
    TTP = AllTime
    local LLT=WizOptionsRev.LLT
    local TXP=UnitXPMax("PLAYER")
    local UXP=UnitXP("PLAYER")
    local AL= TXP - UXP --amount of xp left
    local TPL = string.format('%.2f',TPL) --makes us see a percentage for how much left to level
    local RXP = GetXPExhaustion() -- rested xp
    --to player level math--
    local TPL= string.format("%.2f", (AL / TXP) * 100)
    --rested xp remaining percent math--
    if RXP~=nil then RP = math.floor((RXP / TXP)*100) else RP=0 end
    if tonumber(RP)==0 then TRP=0 end
    TRP=RP
    --temp sanity check for CLT string--
    if CLT==nil then CLT="unknown"
    end
    if LLT==nil then LLT=WizOptionsRev.LLT;end
    if TTP==nil then TTP="unknown" end
    --after clearing the data this tells us what the tooltip will display--
    LvlWizRev_Tooltip:ClearLines()
    LvlWizRev_Tooltip:SetText("|cffffffff"..TPL.."% Remains to achieve a level up.|r");
    LvlWizRev_Tooltip:AddLine("|cff3366ffRested XP left: "..TRP.."% |r");
    LvlWizRev_Tooltip:AddLine("|cff00ff00Time on current level: "..CLT.."|r")
    --LvlWizRev_Tooltip:AddLine("|cFF6495EDEstimated time to level up: "..SecondsToTime(ET).."|r")
    LvlWizRev_Tooltip:AddLine("|cFFAFEEEETime on last level: "..LLT.."|r")
    --LvlWizRev_Tooltip:AddLine("|cFF8A2BE2Kills to level up: "..WizOptions.LM.." Level "..TL.." Mobs".."|r")
    LvlWizRev_Tooltip:AddLine("|cff00ff00Total Time Played: "..TTP.."|r")
    
    LvlWizRev_Tooltip:Show()
    
    end
    


    this is the entire code it's wrapped in

    function ChatFrame_DisplayTimePlayed()
    if (GameTooltip:IsVisible() and GameTooltip:IsOwned(LvlWizRevFrame)) then 
    LvlWizRev_ShowTooltip()
    end
    --WizOptions.TTP = SecondsToTime(arg1)
    --WizOptions.CLT = SecondsToTime(arg2)
    --WizOptions.TIS = arg2
    end
    

    that one pulls the data from the chatframe

    function LvlWizRev_OnUpdate()
    	local since_last_update = GetTime() - prev_update
       	local PT=GetTime()
       LvlWizRev_Update_Freq = LvlWizRev_Update_Freq - 1
       if since_last_update >= prev_update_delay then
       RequestTimePlayed()
       LvlWizRev_ShowTooltip()
       	end
    
    end
    


    and that one updates it periodically

    i also have another RequestTimePlayed() called within my OnShow() function as a means to ensure it's started initially when the addon is brought back up from being turned off ingame.

    it'd be nice if i could make it display like say 1d 2hr 3min or even 1d 2:3:45 or whatever might look nice :P
    Posted in: Lua Code Discussion
  • 0

    posted a message on looking for refrence code
    not exactly... i've been over that call before too, this one's a bit different, gave a nice 3 lines or so of example code.
    Posted in: Lua Code Discussion
  • 0

    posted a message on looking for refrence code
    hi all,

    im looking for a specific refrence code i found in passing on wowwiki that showed information about how to code in lua the conversion of a seconds counter into minutes hours and days. i've used google and wowwiki search to look up this code and have even looked in this new wiki site i found called wowpedia but to no avail.

    if someone could point me in the right direction or at least give me a baseline i could go off of i'd greatly appreciate it :)
    Posted in: Lua Code Discussion
  • 0

    posted a message on not sure where i'm going wrong...
    looks like it worked out and is working perfectly! thanks a bunch! OrionShock i'll make a note of those print requests you can do for debugging this thing while i'm working on it! thanks again! :D
    Posted in: Lua Code Discussion
  • 0

    posted a message on not sure where i'm going wrong...
    thanks for the info guys, i'll try them out and let you know if they worked :) Lao, sorry about not telling you proper on the code. your right, a needs to be true and b needs to be false for the proper things to fire :P
    Posted in: Lua Code Discussion
  • 0

    posted a message on not sure where i'm going wrong...
    hey all,

    i've been trying to rewrite this addon for a while and have run into a pitfall of sorts that i havent been able to figure out on my own no matter how many hours i take a whack at it.

    what i'm essentially trying to do is make it to where my addon responds to changes in the savedvariables file based on two seperate table identifiers. such as when a and b are both true then the addon should be off. but when i try to do that and reload the addon it just opens back up. however the savedvariables file i have confirmed does update apropriately. i'll post the code below:

    function LvlWizRev_BarShow()
    	if  WizOptionsRev.Barenable == false then
    	   LvlWizRevFrame:Hide()
    	  
    	  DEFAULT_CHAT_FRAME:AddMessage(LWR_CSTR_HIDE)
    	else 	  
      LvlWizRevFrame:Show() 
     end
    end
    


    that's what works as intended... but when i add in the line i need denoted below it stops working

    function LvlWizRev_BarShow()
    	if  WizOptionsRev.Barenable == false [COLOR="Red"]and WizOptionsRev.Maxlvl==false[/COLOR] then
    	   LvlWizRevFrame:Hide()
    	  DEFAULT_CHAT_FRAME:AddMessage(LWR_CSTR_HIDE)
    	else 	  
      LvlWizRevFrame:Show() 
     end
    end
    


    i have the following additional things hooked in my OnEvent handlers like so:

    if event=="VARIABLES_LOADED" then
    
    -- should tell itself if you are max level and set apropriate value
    LvlWizRev_LvlisMax()
    -- decides if the bar should be shown
    LvlWizRev_BarShow()
    end
    


    also just for refrence here is the LvlWizRev_LvlisMax() code
    function LvlWizRev_LvlisMax()
       if UnitLevel("player")==85 then
    WizOptionsRev.Maxlvl=true
    WizOptionsRev.Barenable=false
    LvlWizRevFrame:Hide()
    else
    WizOptionsRev.Maxlvl=false
    end
    end
    


    any help is greatly appreciated, thanks! :)
    Posted in: Lua Code Discussion
  • To post a comment, please or register a new account.