Equip Recommended Gear

Equip Recommended Gear

3.5k Downloads

DoTheThing() Prints Output Incorrectly

Saaappi opened this issue · 12 comments

commented

Description
When calling the DoTheThing() function with an argument value of 1, the function incorrectly prints output to the chat frame. According to the function's intended behavior, it should only print output to the chat frame when no argument is supplied.

Steps to Reproduce

  1. Call the DoTheThing() function with an argument value of 1.
  2. Observe the output printed to the chat frame.
commented

Which output does it print?

It should only print a message when it is equipping recommended gear when the argument is 1, but not print a message when the player is already equipped with the recommended gear.

If you want no messages at all, the argument provided should be 0.

commented

It's changing msg to 2, despite me passing 1 to the function. I tested it outside my code by typing it in and received the same behavior.

In other words, I'm passing 1 but DoTheThing is ignoring that and setting it to 2. Are you resetting msg at some point higher up in the function? 🧐

commented
-- Set the message variable if it's not set (properly)
if not msg then
	msg = 2
end
if type(msg) ~= "number" then
	msg = 2
end

This is the input sanitisation I'm using. You're not passing the number to the function as a string, right?

commented

Very weird. I'll have to test this some more when I get home then, but when I tested it upon implementation it was behaving fully as expected.

commented

Nope. Type is number.

commented

local function ERG()
if UnitAffectingCombat("player") then
C_Timer.After(1, ERG)
else
if IsAddOnLoaded("EquipRecommendedGear") then
EquipRecommendedGear:DoTheThing(1)
end
end
end

I'm on mobile, so I can't format the code here. This is all I'm doing when calling your code.

commented

Using : instead of . shouldn't matter, right? Again, I'll look into it when I get home tonight. :)

commented

: is used when a function passes self as the first parameter. A and B are the same.

A
sky.foo(a, b)

B
sky:foo(self, a, b)

It's syntactic sugar, that's all.

commented

By your logic, wouldn't it pass self instead of 1 to the function in your code, then?

commented

Hmmm... after reviewing your code I can see that you implement functions differently than I do (particularly those stored in tables).

So, you're probably right that, in this case, there's a difference.

I'll change my code tomorrow and test. If it works, then I'll close this issue out. 🫣

commented

Show me how you do that in your code, sometime! I'm still learning new stuff all the time. :D

commented

Closed! Changing : to . fixed it.