Blizzard, Lua, and Addons.

After a rather amusing Twitter discussion, I realized that the little addon I wrote back in Wrath of the Lich King, to make sure I used Focus Magic, Mark of the Wild, and Trueshot Aura, when on those alts, was still something that was clearly needed for some in Cataclysm.

I hadn’t updated it, because honestly, I didn’t care. I only raid/run dungeons on 2-3 toons now (as opposed to Wrath when I ran the daily dungeon on *every.single.toon*) and so I didn’t need the reminders as much.

After someone mentioned wanting an addon to remind them to take off their chef’s hat, and someone else brought up the Dalaran rings, and then someone else mentioned forgetting their pets, it was clear I needed to buckle down and fix up my addon.

The things I learned this weekend:

1. I hate Lua when compared to the scripting language I use at work.

2. And/Or checks are always the first place to look for a mistake.

 

I got started by trying to figure out how to check for low level items. I hard coded it to pop on anything below item level 300 for a level 85. Seemed like a good marker for Cataclysm. I already did hard coded checks for Chef’s Hat, all Fishing Poles, and Dalaran Rings. If it found any, it would boot it out and give the player some snarky comment in their chat box about the item.

Then I hit my first problem. The little loop would run along fine, until it hit my character’s shirt slot. For those who don’t play WoW, there is a chest slot for armor, and a shirt slot for a shirt. The shirts in the game are a very specific piece of gear that is only worn there, and has no stats. So in this instance, it didn’t matter at all. My character doesn’t even *wear* a shirt, that’s how unimportant it is.

And that’s what caused the problem. See, the script would return nil on the shirt, then break trying to compare the nil value to 300. So I tried what I would have done at work. Essentially saying check the slot and if it’s the shirt, ignore it, and keep going. This would mean that it would never return on the shirt. This lead me to discover 2 things: 1. There is no way to get the slot number for a specific slot on the equipment screen without either just using it’s number or using it’s string name. This means I had to hard code it to just say, if it’s slot 4, keep going. Which lead me to number 2. Lua doesn’t have a “continue.” There is no way to say ignore this, and keep going on the loop, if it returns nil. So I had to go up and say, if this is nil AND this is slot 4, then handle the exception so it wouldn’t break the loop.

Now yes, I understand that it is good programming to handle exceptions like that, but at work, I could have simply scripted it to say, if nil, flow out 2. Meaning, if this would break, we are just going to ignore it, and move on to the next iteration of the loop. Is the way I was forced to code it better? Sure, it means that I know every single exception and deal with it. It means that if an item isn’t equipped, and one *should* be, then yes, it should return a warning.

After getting this running, I tried it out on several of my characters. It worked great. Sure, it got a bit spammy, and it would instantly remind you as soon as you equipped your fishing pole, but it seemed to do what I needed it to do.

So then I tested by logging on to several of my alts. All good, all good. OMG SPAM FROM HELL. I had logged onto my druid. My level 85 druid, who had exactly one item over level 300. I had gotten her to level 85, but I hadn’t even thought about her gear. So she had horrible gear.

Time to rethink my design.

So I went back to the code and instead, pulled the average item level (the same one used for queuing for dungeons) and instead checked to see if all your gear was within 30 points of that average. If it was lower, then it would warn you. This worked much better.

Alright, so on to testing.

As I played, I noticed something very odd. I was using an event, essentially a thing that triggers when something happens in game, called Player_Enters_World to recheck all the stuff RememberAll was supposed to be checking. This way, every time you hit a loading screen it would remind you of all the stuff you might need to change.

But every time you loaded in, it would trigger 3 times. I also noted that the information coming from my addon was doing very weird things. Including spamming once, correctly, then spamming a second time, only this time saying you were missing all the buffs you should have had, regardless of if you had them or not, then spamming a third time, once more missing all buffs.

As it turns out, when a player in WoW hitsĀ  a load screen, they are unloaded from their current zone, triggering the Player_Entering_World event for some reason, load into a “void zone” where the player exists, but they do not have buffs, etc, and then loading from there into the actual world, once it has been loaded in.

 

Leave a Reply