• 0

    posted a message on .lua working with numbers
    currentTotal = (currentTotal or 0) + currentTotal

    That's because with this line of code your doubling it. What you want to do is not double it, but set your SV to it. You might be running into scoping issues if your variable names are all the same.
    Posted in: Lua Code Discussion
  • 0

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


    Why would event equal one thing and then, with nothing changed, equal something else on the next line of code?
    Posted in: Lua Code Discussion
  • 0

    posted a message on .lua working with numbers
    Quote from egingell
    P.S. Logic errors are a bitch to debug because you (usually) don't get any error messages.

    On that same note, to debug logic errors the easiest thing to do is break it apart into as many as needed "If then else end"s as needed or break all your variable movement into one step at a time and use print() & then optimize from there.
    Posted in: Lua Code Discussion
  • 0

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

    Thank you, let me test.


    never used javascript actually
    Posted in: Lua Code Discussion
  • 0

    posted a message on .lua working with numbers
    Quote from lilsparky
    fwiw, you probably need a few "tonumber()"s in there to convert your string selections to numbers.


    prolly not..



    function guildLoot_OnEvent(self, event, msg)
    	if event == "CHAT_MSG_MONEY" then
    		local guild = msg:match( "%((.+)%)")
    		if not guild then return end
    
    		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
    		---Set your value in your db or SV at this point
    		SavedVariableName = (SavedVariableName or 0) + currentTotal
    		----
    		lootAmounts:AddMessage( GetCoinTextureString( SavedVariableName ) )
    
    	end
    end


    oh yes, you can mix logic and math together like that :)
    Posted in: Lua Code Discussion
  • 0

    posted a message on .lua working with numbers
    Quote from wwwDot
    WOOW. Thank you both, so effin much lol.

    I have to reload wow before i can test because of lag spikes.

    But i also had a few more question's..

    For some reason my icon doesn't show for my minimap button, it's just a clear button, and i also can't get it to stay in the spot the user move's it to. It always goes back to the top left of the minimap.


    that's a combo between how you save the frame position and what you code looks like.

    IMO ditch the minimap icon and go for LDB plugin instead. Much simpler and nicer to everyone else :) and you can still have you minimap button via libdbicon

    However if you must with a minimap button, i think this link will help, there is code at the bottom to help.
    Posted in: Lua Code Discussion
  • 0

    posted a message on .lua working with numbers
    @egingell
     local _, guild = msg:match( "(.+)%((.+)%)" ) 

    Is a hold over from my example, that is a hold over from something previous, your suggestion is better. It also allows for when your in group and someone else loots :)
    --Edit: you may want to also check for nil values if you only grab the part in the ( )

    @OP all you need is this line to simply your math, lua is smart :)
    local currentTotal = currentTotal + (gold*1000) + (silver*100) + copper
    lootAmounts:AddMessage( GetCoinTextureString( currentTotal ) )


    That the new amount being added might be 0 is unimportant. Lua evaluates expressions right onto left. So you can update a variable while adding the previous value of that variable to it.
    Posted in: Lua Code Discussion
  • 0

    posted a message on Guild Deposit Loot String?
    Quote from wwwDot
    Would they be considered event's? or would you need it to check the chat box when you loot or something like that?


    9/10 things in the chat box is an event, in this case the event "CHAT_MSG_MONEY"
    Posted in: Lua Code Discussion
  • 0

    posted a message on API function to return character sobriety?
    Quote from Thanah

    Is it possible to "join" the addonmessage channel so I can keep an eye on the mods talking to each other (for testing purposes)?


    Sure, for testing you can. but considered bad form if you leave it in.


    do	------------	Show Addon Messages in ChatFrame 5	------------
    	local eventFrame = CreateFrame("Frame")
    	eventFrame:RegisterEvent("CHAT_MSG_ADDON")
    	local ignore = {
    		["GSY"] = true,	--Gear Score
    		["DS_Craft"] = true,	--DataStore
    		["DS_Inv"] = true,
    		["DS_Cont"] = true,
    		["DataStore"] = true,
    		["WIM"] = true,	--WoWInstantMessenger
    		["DBMv4-Ver"] = true,	--DBM Spam
    	}
    	local fmt = ("|cff33CCFF[%s]|r|cffFFFF00[%s]|r|cffFF6666[%s]|r|cffFF99CC[%s]|r")
    	function eventFrame:CHAT_MSG_ADDON(event, prefix, msg, distro, sender)
    		prefix,msg,distro,sender = tostringall(prefix,msg,distro,sender)
    		if not ignore[prefix] then
    			ChatFrame5:AddMessage( fmt:format(prefix,distro,sender,msg) )
    		end
    	end
    	local fmtW = ("|cff33CCFF[%s]|r=>|cffFFFF00[%s]|r|cffFFFF33[%s]|r|cffFF99CC[%s]|r")
    	hooksecurefunc("SendAddonMessage", function(prefix,msg,distro,who)
    		prefix,msg,distro,who = tostringall(prefix,msg,distro,who)
    		if distro:upper() == "WHISPER" then
    			ChatFrame5:AddMessage( fmtW:format(distro,who,prefix,msg) )
    		end
    	end)
    end	------------------------------------------------------------------------
    
    Posted in: AddOn HELP!
  • 0

    posted a message on Guild Deposit Loot String?
    local GOLD = GOLD_AMOUNT:gsub("%%d", "%(%%d+%)")
    local SILVER = SILVER_AMOUNT:gsub("%%d", "%(%%d+%)")
    local COPPER = COPPER_AMOUNT:gsub("%%d", "%(%%d+%)")
    
    function addon:CHAT_MSG_MONEY(event, msg, ...)
    	local _, guild = msg:match( "(.+)%((.+)%)" )
    
    	local gold = guild:match(GOLD) or 0
    	local silver = 	guild:match(SILVER) or 0
    	local copper = guild:match(COPPER) or 0
    
    	local total = (gold*1000) + (silver*100) + copper
    
    	print( GetCoinTextureString( total ) )
    end
    Posted in: Lua Code Discussion
  • 0

    posted a message on Broker Currency
    Quote from Torhal
    I'm leery of doing something of this manner: Then people will start asking to track money spent on flightmasters, repairs, etc...and this suddenly turns into a competitor for Auditor.


    True. Will have to write my own
    Posted in: Data Broker AddOns
  • 0

    posted a message on Broker Currency
    Can Broker Currency be changed so it can also track contributions made to the guild bank?
    Posted in: Data Broker AddOns
  • 0

    posted a message on Officially stumped
    @ your database synch methods, using time() is not useful. [[ date("!%Y%m%d%H%M") ]] was a more effective way of tracking time with guilds in several timezones. Also looking over your scanning method for the guild bank brings back memories from when i wrote the link scanning code for GuildCraft... tis a mess of a problem.
    Posted in: Lua Code Discussion
  • 0

    posted a message on Officially stumped
    On your Comms function. separate it out. I did something like this for GuildCraft.. granted i didn't use LibCompress because it wasn't needed.

    IE:
    [php]
    local function HandleComms(distro, sender, success, command, ...)
    if success and lib[command] then
    lib[command](lib, command, distro, sender, ...)
    --- This format of calling the function just keeps things consistant
    --- with how the WoW Event handler & CBH works. "command" basically
    --- is the event in this case :)
    end
    end

    function lib:OnCommReceived(prefix, msg, distro, sender)
    if prefix == "LGB" then
    local data, err = LibCompress:Decompress(msg)
    if not err then
    HandleComms(distro, sender, lib:Deserialize(data) )
    end
    end
    end
    [/php]

    You can also create helper functions like this:

    [php]

    function lib:SendGuildMessage(distro, target, command, ...)
    local data = self:Serialize(command, ...)
    local compressed = LibCompress:Compress(data)
    self:SendAddonMessage(addon_prefix, data, distro, target)
    ---- ^^ This is the Ace3Comms function
    end
    [/php]

    These sort of functions help with the replication of code in various places. This allows you to throw data around clients consistently. You don't have to worry about 3 functions that send data doing it differently.

    ------
    On methodology, i would stop caring about a player's rank and what parts of the guild bank they can see. There is a lot of backwards event logic behind this idea mostly due to how WoW handles these things. I would just give up on it and only filter stuff when you actually go to use the data if anything.
    Posted in: Lua Code Discussion
  • To post a comment, please or register a new account.