找回密码
 立即注册

手机短信,快捷登录

搜索

WA Dev Debug Messages

[复制链接]
 楼主| 发表于 2023-6-12 09:44:36 | 显示全部楼层 |阅读模式
What is this?
This aura facilitates easy debug messages for WeakAura developers. Ever since I've recently started learning how to use custom code in WeakAuras, I've found that one common thing over all my projects is the need to have robust debug code during development. It started as a simple "print" function that I included in all my projects and has grown to be very versatile and robust over time. I figured I'd package it up for public use and share it for other WA devs.

Features
>"Detached"
    You only need to include minimal code to in your own auras as pretty much everything is handled "remotely" via WeakAuras.ScanEvent().
>Message "Groups"
    Define different types of messages each with different formatting. Reuse these message groups over multiple projects. Easily Enable/Disable all messages in a group.
     "templates" would've been a more descriptive name but I can't be arsed to change it at this point
>Automatic Key/Value Pair Printing
    Most of the time a debug message is made to print out variable values at different points of execution. This helps simplify that process (and helps make table output readable as well).
>All output is ran through tostring() first to prevent any issues with nil values or different data types
    I don't know about you but there were many times where I was trying to find a bug and it turned out to be the debug message itself
>Reroute output to another chatframe
    The only way to route output to a chatwindow other than the default is via https://wowwiki.fandom.com/wiki/API_MessageFrame_AddMessage , (thanks to asakawa for pointing this function out to me) which has a lot more limitations than print(). This makes it easy to switch between chat frames and is also pretty much seamless.
>It looks nice!
    and it's also easy to customize via the User Options interface

Usage
    > Just have this aura installed and loaded; It responds to "DPRINT" events sent by any other aura.
    > Fire an event with:

    WeakAuras.ScanEvents("DPRINT", groupName, prefix, message, ...)

         - groupName is the message template you want to use for the debug message
         - prefix will prefix the message sent (I personally send 'aura_env.id' as the prefix so I know which aura each message is coming from) You can disable prefixes in User Options
         - All additional args after "message" will print in a key/value format automatically. (ie, odd args will print as keys, even args will print as values, pairs print on separate lines)
         - You can enable/disable this behavior in User Options
         - Additionally, you can specify "keywords" to print out all arguments after that keyword as values. (ie, printing out a list of args)

    > This is the function I personally put at the top of all my projects:

    aura_env.debug_print = function(group,msg,...)
    return WeakAuras.ScanEvents("DPRINT",group,aura_env.id,msg,...)
   end

    Obviously you can make it a local function or name it whatever you want for less typing.

    >Some examples:
    A debug message with some key/value pairs:

    aura_env.debug_print("fail", "Something bad happened!", "Variable 1", var1, "Variable 2", var2)

    A debug message using a "keyword" to stop printing as pairs:

    aura_env.debug_print("warning", "Something iffy happened!", "Variable 1", var1, "Variable 2", var2, "args", arg1,arg2,arg3)

Everything else should be pretty self explanatory.
I also included a demo aura that shows off how it works. It triggers demo debug messages from: player movement, player target change, modifier key pressed, player spell cast start and spell cast success
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|魔兽世界玩家社区APP官网 ( 鄂ICP备20007009号-6 )

GMT+8, 2025-7-11 09:50 , Processed in 0.233679 second(s), 7 queries , Redis On.

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表