1. #1

    [WEAKAURAS] Need help with snapshotting health in LUA

    Hi,

    so this is my problem. I have created this if statement (just copied 1 line from it, cause you dont need more to understand it), but its not working the way I want it too. This is my current statement:

    if (UnitHealth("player") == UnitHealth("player")) then

    What I want to achieve is something like the statement below where it snapshots the current health and compares it to the current health.

    if (UnitHealth("player") == SNAPSHOT_CURRENT_UnitHealth("player") then

    Is there a simple way to do this with some variables? Or does anyone have a smart solution to this problem?
    Thanks in advance!

  2. #2
    Quote Originally Posted by peterparker View Post
    What I want to achieve is something like the statement below where it snapshots the current health and compares it to the current health.
    That doesn't make sense to me. Elaborate please.
    Last edited by Woogs; 2014-07-17 at 01:26 AM.

  3. #3
    *evn, thanks buddy, problem solved! I thought saving (UnitHealth("player") in a variable would dynamically update the variable aswell, but it doesnt

    *Woogs, this is what I really was trying to do (I simplified it a bit):

    if Touch of karma is up and I am not taking any damage
    show percentage of how much damage I am taking compared to my current max health

    elseif touch of karma is up and I am taking damage
    show message "danger"

    to check if I was taking damage or not I couldnt use if (UnitHealth("player") == UnitHealthMax("player")) then, because UnitHealthMax only showed my max total health (100%), regardless of the fact if I had 90% health at that moment. So what i wanted to store this 90% health somewhere and compare it to my updating current health.
    Last edited by peterparker; 2014-07-17 at 04:25 PM.

  4. #4
    A closure would not be ideal for what you describe because there is no need to store an internal state. Your example using a ternary statement in Lua syntax:
    Code:
    foo = function() return UnitHealth("player") > UnitHealth("target") and UnitName("player") or UnitName("target") end

Posting Permissions

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