• 0

    posted a message on .lua working with numbers
    I have been trying to get my variable saved, but it just won't happen.

    In my .toc it is:

    ## SavedVariablesPerCharacter: currentTotal


    and to save it i tried:

    elseif event == "PLAYER_LOGOUT" then
    		currentTotal = true
    	end


    But it just reload's at the restart of the AddOn.
    Posted in: Lua Code Discussion
  • 0

    posted a message on .lua working with numbers
    Lol. It's 4:30 am, i'm super tired, but i want to get this to save the variable. And it just won't, everything i try, is a fail right now lol.
    Posted in: Lua Code Discussion
  • 0

    posted a message on .lua working with numbers
    BUT, now it doesn't save when logging out lol.
    Posted in: Lua Code Discussion
  • 0

    posted a message on .lua working with numbers
    Quote from OrionShock
    But has your understanding increased ?

    that is all that really matters :)


    Yes, yes it has.
    Posted in: Lua Code Discussion
  • 0

    posted a message on .lua working with numbers
    One thing i don't like about asking for help lol..........

    Now i can't say i did this.

    And you have done it, because of me asking question's lol. :/

    /edit

    But thank's for the cookie :)
    Posted in: Lua Code Discussion
  • 0

    posted a message on .lua working with numbers
    I just answered my own question, but would this be it?

    function guildLoot_OnEvent(self, event, msg)
    if event == "ADDON_LOADED" then
    keepVarTot = keepVarTot or 0
    else
    if event == "CHAT_MSG_MONEY" then
    local _, guild = msg:match( "(.+)%((.+)%)" )
    
    local gold = guild:match(goldLoot) or 0
    local silver = 	guild:match(silverLoot) or 0
    local copper = guild:match(copperLoot) or 0
    			
    keepVarTot = (keepVarTot or 0) + (gold*1000) + (silver*100) + copper
    			
    lootAmounts:SetText("You have looted " .. GetCoinTextureString( keepVarTot ) .. " for your guild bank." )
    elseif event == "PLAYER_LOGOUT" then
    keepVarTot = keepVarTot or 0
    end
    end
    end
    Posted in: Lua Code Discussion
  • 0

    posted a message on .lua working with numbers
    Quote from egingell
    I've seen worse. At least he's trying. lol


    Sweet, I'm not the worst, lol.
    Posted in: Lua Code Discussion
  • 0

    posted a message on .lua working with numbers
    I would love a cookie lol.

    And that did work, and it's now adding correctly.

    Would i need to call for a PLAYER_LOGOUT, to make sure the AddOn save's the variable, or will that not matter?
    Posted in: Lua Code Discussion
  • 0

    posted a message on .lua working with numbers
    Ok. I think that fixed it, about to test now.

    Maybe i should make a mental note to tell me, not to write lua coding when tired.

    You guy's should have seen the monstrosity of an idea i was about to try before checking the thread lol.
    Posted in: Lua Code Discussion
  • 0

    posted a message on .lua working with numbers
    So if i were to change the saved variable name to say, keepVarTot, i would have to do this?

    local currentTotal = (keepVarTot or 0) + currentTotal
    			currentTotal = (gold*1000) + (silver*100) + copper
    			keepVarTot = currentTotal
    			lootAmounts:SetText("You have looted " .. GetCoinTextureString( keepVarTot ) .. " for your guild bank." )
    Posted in: Lua Code Discussion
  • 0

    posted a message on .lua working with numbers
    Changing it to:

    local currentTotal = (currentTotal or 0) + currentTotal
    			currentTotal = (gold*1000) + (silver*100) + copper
    
    			lootAmounts:SetText("You have looted " .. GetCoinTextureString( currentTotal ) .. " for your guild bank." )


    Stopped the doubling, but it still does add the previous and new amount's and print the sum.
    Posted in: Lua Code Discussion
  • 0

    posted a message on .lua working with numbers
    Quote from OrionShock
    Why would event equal one thing and then, with nothing changed, equal something else on the next line of code?


    Good point ;)

    function guildLoot_OnEvent(self, event, msg)
    	if event == "ADDON_LOADED" then
    		print("GuildLoot has been loaded.")
    	end
    		if event == "CHAT_MSG_MONEY" then
    			local _, guild = msg:match( "(.+)%((.+)%)" )
    
    			local gold = guild:match(goldLoot) or 0
    			local silver = 	guild:match(silverLoot) or 0
    			local copper = guild:match(copperLoot) or 0
    
    			local currentTotal = (gold*1000) + (silver*100) + copper
    			currentTotal = (currentTotal or 0) + currentTotal
    			upgradeTotal = currentTotal
    
    			lootAmounts:SetText("You have looted " .. GetCoinTextureString( upgradeTotal ) .. " for your guild bank." )
    		end
    end


    Caused it to print it was loaded 8 time's, and the loot info now double's each loot amount, and still doesn't add to the next loot.
    Posted in: Lua Code Discussion
  • 0

    posted a message on .lua working with numbers
    Am i using ADDON_LOADED correctly?

    function guildLoot_OnLoad(self)
    	self:Hide()
    	self:RegisterEvent("CHAT_MSG_MONEY")
    	self:RegisterEvent("ADDON_LOADED")
    end
    
    function guildLoot_OnEvent(self, event, msg)
    	if event == "ADDON_LOADED" then
    		if event == "CHAT_MSG_MONEY" then
    			local _, guild = msg:match( "(.+)%((.+)%)" )
    
    			local gold = guild:match(goldLoot) or 0
    			local silver = 	guild:match(silverLoot) or 0
    			local copper = guild:match(copperLoot) or 0
    
    			local currentTotal = (gold*1000) + (silver*100) + copper
    			currentTotal = (currentTotal or 0) + currentTotal
    
    			lootAmounts:SetText("You have looted " .. GetCoinTextureString( currentTotal ) .. " for your guild bank." )
    		end
    	end
    end


    Because it isn't printing the currentTotal to the frame now.
    Posted in: Lua Code Discussion
  • 0

    posted a message on .lua working with numbers
    Ahh, well this is a lot better lol, very smarter.

    And i got confused lol. It's 3 am, and i think i did this wrong lol.

    Does SavedVariableName need to be changed to the savedvariable it is trying to read?
    Posted in: Lua Code Discussion
  • 0

    posted a message on .lua working with numbers
    You are just loving how this is so much better the javascript, huh? Lol

    Thank you, let me test.
    Posted in: Lua Code Discussion
  • To post a comment, please or register a new account.