Thread Tools Display Modes
04-16-20, 03:06 AM   #1
Kurtain
A Defias Bandit
Join Date: Apr 2020
Posts: 3
Simple tracking scrips

Im making an automatic tracker for an alt with both herbalism and mining! This is my first WoW addon, and got no experience with LUA or wow API before this.

In my LUA code ive got a a function that repeats every 4 seconds, which work perfectly until i login in a rested zone (inn or capital).

this is the function:
Code:
local function tracking()
    if UnitIsEnemy("player","target") then
    else
        if IsResting() then
        else
            if i == 0 then
                CastSpellByID(2580);
                i = i + 1;
            elseif i == 1 then
                CastSpellByID(2383);
                i = i - 1;
            end
        end
    end
end
As you can see Ive made it so if im targeting a hostile monster it shouldnt loop, so i dont get GCDs when Im fighting, ive also added so i dont use it while getting rested, to not screw with me while doing stuff in capitals.

the way I run the function is:

Code:
if IsSpellKnown(2580) and IsSpellKnown(2383) then
    C_Timer.NewTicker(4, tracking)
end
This works if I login out in the wilds, when entring an inn It will not do any new tracking, and when exiting it will continue the trackingloop.
When I login into the same inn the tracking will not change after leaving the inn and do a /reload

Are there any obvious things Ive missed?
  Reply With Quote
04-16-20, 11:48 AM   #2
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Where's the rest of your code?
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
04-17-20, 07:52 AM   #3
Kurtain
A Defias Bandit
Join Date: Apr 2020
Posts: 3
Other than my .toc file there are nothing else, except a decleration of i, in the global scope.
  Reply With Quote
04-17-20, 09:02 AM   #4
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,871
The global space is shared by the entire Blizzard UI and all the 3rd party addons you have installed. Naming a global variable "i" is not a great idea as it's too easy for it to be "trampled" by someone missing a "local" declaration by accident.

Code:
local Mining, Herbing = 2580, 2383
local FindHerbs
local function tracking()
	if not UnitIsEnemy("player","target") and not IsResting() then
		FindHerbs = not FindHerbs
		if FindHerbs then
			CastSpellByID(Herbing)
		else
			CastSpellByID(Mining)
		end
	end
end
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
04-17-20, 03:24 PM   #5
Kurtain
A Defias Bandit
Join Date: Apr 2020
Posts: 3
ok, i probably misspoke; i declared i as:
Code:
local var i = 0;
I will however try your code and see if that would work tomorrow! thanks!
  Reply With Quote
04-18-20, 11:46 AM   #6
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Do you mean this? What you put above is not proper syntax.
Lua Code:
  1. local i = 0
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Simple tracking scrips

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off