Quantcast
WoWInterface - View Single Post - Attempting to track emotes performed on targets.
View Single Post
03-29-18, 08:48 PM   #5
Kanegasi
A Molten Giant
 
Kanegasi's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2007
Posts: 529
When you first use this code, the loop doesn't do anything because the table is empty. There's nothing to loop through, so that if statement never happens.

Instead of a loop, use a ternary statement:

Lua Code:
  1. if emotetype == "BONK" then
  2.     --print("Success")
  3.     bonktrack[btname] = bonktrack[btname] and bonktrack[btname]+1 or 1
  4.     print("BONKed " .. btname .. " " .. bonktrack[btname] .. " times")
  5. else
  6.     print("BONK fail")
  7. end

The line after the commented print is called a ternary statement or operator. I have also seen "logic shorthand". When Lua parses this, which is variable = logic statement, it skips the rest of it when it reaches something true and returns the value of the last part of the true statement, whether it's true itself (the boolean value) or a non-false/non-nil value (result of math, another variable, the return from a function, etc). In this case, if there's a value at bonktrack[btname], it returns that value+1 into that key. If that key is nil, it skips the +1 and just sets it at 1.

Last edited by Kanegasi : 03-29-18 at 08:51 PM.
  Reply With Quote