This site makes extensive use of JavaScript.
Please enable JavaScript in your browser.
Live
PTR
10.2.7
PTR
10.2.6
Beta
Small Lua Question
Post Reply
Return to board index
Post by
Mosrael
I've been trying to understand lua so that I could have more control over my UI, but I've run into a problem that I couldn't Google...
I want my TargetTarget to show an ! on it's frame when it is targeting me.
A friend suggested this, but it didn't work.
if IsUnit('player', Target) then '!' end
I'm extremely bad at lua and wouldn't even know if it needed to have 's around it like DogTags.
Post by
Wanderingfox
LuaTexts (which is what I assume you're trying to work with) are essentially a function without the function wrapper around them.
That is to say that what you enter is actually being wrapped by:
function f(...)
<what you type into the luatext box>
end
The reason your code does not work is that it's not returning anything. Your just saying "if this then !", but that's not actually DOING anything you're just stating a fact. Just having " '!' " there is like saying "if this then a is a" It's not telling the computer to do anything.
What you're looking for is something like this:
if IsUnit('player', Target) then return '!' end
Note the addition of the word 'return' which is telling the function what it should send back to the caller when it's executed. In this case you want it to return '!' so that text is shown on the frame.
Post by
Mosrael
if IsUnit('player', Target) then return '!' end
Produced quite a bit of errors. I'm using Stuf unitframes. Maybe something is conflicting with it?
Edit - Hmm, maybe not. I turned off all addons except for Stuf and the error persists.
Post by
HighFive
There is no "IsUnit" function (not by default anyway). You probably wanted to use "UnitIsUnit".
Also, you unless you defined "Target" as a string it's gonna return errors.
Try this:if UnitIsUnit('player', 'targettarget') then return '!' end
Post by
Mosrael
Nope, still assaulted with errors.
Post by
Wanderingfox
There is no "IsUnit" function (not by default anyway). You probably wanted to use "UnitIsUnit".
Also, you unless you defined "Target" as a string it's gonna return errors.
Try this:if UnitIsUnit('player', 'targettarget') then return '!' end
I knew that looked a little odd. This is what I get for just trusting other people's code :P
As for why that won't work either... Is Stuf actually using Luatexts, or is it some other implementation of something similar? There may be a specific type of return that it's looking for outside of just a string :/
Post by
Mosrael
I think it is Luatexts.
Is it possible to do this with kgpanels? Maybe put a panel on top of the frame with the lua in it?
Post by
HighFive
Is Stuf actually using LuatextsApparently not.
@OP, Try this:function() return UnitIsUnit('player', 'targettarget') and '!' endAlso, check "Frequent Updated". Otherwise it will only update on target change.
Post by
Mosrael
That
works
. Wanderingfox and HighFive, thanks for the help.
Post by
rakkarage
i am having a similar problem... in cowtip luatext
if UnitIsUnit('targettarget', 'player') then
return '> Self!'
end
works, but
if UnitIsUnit('mouseovertarget', 'mouseover') then
return '> Self!'
end
does not... according to
http://www.wowwiki.com/API_UnitIsUnit
http://www.wowwiki.com/UnitId
mouseovertarget is a valid unitid?
Post by
HighFive
Yes it is.
You are checking if your mouseover is targeting himself. Is that what you're trying to accomplish or should that be "UnitIsUnit('mouseovertarget', 'player')"?
Post by
pelf
@OP, Try this:function() return UnitIsUnit('player', 'targettarget') and '!' endAlso, check "Frequent Updated". Otherwise it will only update on target change.
Hmm, if that method worked I don't think we're quite grokking the way the luatexts are supposed to be written. Feels like it works just because it manages to mash into the mold without being the right form, really.
Post by
HighFive
I thought rakkarage just posted the relevant part of the code. This shouldn't work by itself, of course.
Post by
pelf
Sorry, bad antecedent. Fixing.
Post by
HighFive
Oh. The thing is, Stuf doesn't use LuaTexts but some implementation of its own. And from the short research I did that is the correct syntax. I think it would also mold into LuaTexts also though.
Post by
pelf
Hmm. That's really odd/gross syntax.
Post Reply
You are not logged in. Please
log in
to post a reply or
register
if you don't already have an account.