1. #1

    Lua function question

    I have a question for all you lua experts.

    Here are two functions that do exactly the same thing. They return the name of a person who used interrupted successfully. Both functions have the same body but their headers are different. Many variables are not on same position (example would be "timestamp" in second code is on second place, while in first code its on fourth place).
    So how does this work, can you just put variable names wherever or would i get an error if i try to get "time" from one of these two functions.

    Code:
    function (_, _, token, time, who_serial, who_name, who_flags, _, alvo_serial, alvo_name, alvo_flags, _, spellid, spellname, spelltype, extraSpellID, extraSpellName, extraSchool)
        
        if(token == "SPELL_INTERRUPT") then
            name = who_name
            return true
        end
    end
    Code:
    function(event, timestamp, message, hideCaster, sourceGUID, sourceName, sourceFlags, sourceRaidFlags, destGUID, destName, destFlags, destRaidFlags, ...)  
       
        if message == "SPELL_INTERRUPT" then
            sname = sourceName
            return true
        end
    end
    Note, both of the functions work flawlessly for tracking interrupts. I'm just curious why they are so much different.

  2. #2
    Both functions are receiving the same arguments in the same order. You assign them to local variables in the function signature. The first function creator mistakenly thought the fourth argument was the timestamp.

  3. #3
    thanks for clearing it up.

    One more question. when i create custom functions using events, is this the proper way to do it?

    Code:
    function(event, eventArguments...)
       ...
    end
    first argument being the event that we use, second argument (and rest if there are more) are arguments of that event
    Last edited by Parach; 2016-10-05 at 10:33 PM.

  4. #4
    Code:
    function(arg1, ...)
    	local numArgs = select("#", ...)
    	local arg2 = select(1, ...)
    	local arg3 = select(2, ...)
    end

  5. #5
    Are you referring to WeakAura functions/triggers?

    Anyway this Wowpedia page could be useful
    http://wow.gamepedia.com/COMBAT_LOG_EVENT

  6. #6
    I was talking about custom triggers in WA, yes.

  7. #7
    Quote Originally Posted by Woogs View Post
    Code:
    function(arg1, ...)
    local numArgs = select("#", ...)
    local arg2 = select(1, ...)
    local arg3 = select(2, ...)
    end
    Using select for that matter is bad. It's using more cpu than just put the variables to local with right order.
    So use:
    local event, time, andsoon = ...
    Depending on the variables of course.

  8. #8
    Quote Originally Posted by Defmaster View Post
    Using select for that matter is bad. It's using more cpu than just put the variables to local with right order.
    So use:
    local event, time, andsoon = ...
    Depending on the variables of course.
    For that, you can just skip the vararg altogether:

    function(event,time,andsoon)
    Originally Posted by Zarhym (Blue Tracker)
    this thread is a waste of internet

  9. #9
    Quote Originally Posted by Defmaster View Post
    Using select for that matter is bad. It's using more cpu than just put the variables to local with right order.
    So use:
    local event, time, andsoon = ...
    Depending on the variables of course.
    That example was just to show Parach how to work with varargs. Some examples of when you would want to use select.

    Code:
    function(...)
    	local arg7 = select(7, ...) -- looks cleaner than underscore dummying
    end
    
    function(...)
    	for i = 1, select("#", ...) do
    		local arg = select(i, ...)
    	end
    end
    Last edited by Woogs; 2016-10-06 at 04:27 PM.

  10. #10
    One more question. When person from another server interrupts, WA shows "playerName - serverName Interrupted!" Is it possible to hide server name in any way?

  11. #11
    Yes, there is two ways, but since you haven't given the full weakaura, I can't really give you exactly what will do that for you. However, I will assume the functions you have given in your first post is what gives the names. I don't know which one you used, so I'll change both.

    In each, there is a name line:

    name = who_name

    and

    sname = sourceName

    Depending on which function you used, change the line to the following:

    name = string.match(who_name,"(.*)%-?")

    or

    sname = string.match(sourceName,"(.*)%-?")

    Use whichever one goes with the function you used. If you want more detailed help or this change doesn't work, please provide the full code you need help on. In the future, always provide the full code when asking for help. If the code is too large, use pastebin or wago.io and link it.
    Last edited by Kanegasi; 2016-10-09 at 05:09 PM.
    Originally Posted by Zarhym (Blue Tracker)
    this thread is a waste of internet

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •