SetTextTagPermanent lets Floating Text disappear

Level 15
Joined
Jul 10, 2009
Messages
347
Hey guys,

I'm currently facing an issue with a texttag that vanishes after using SetTextTagPermanent(texttag, false) immediately after creation.

Precisely, the following code will create a working texttag with restricted lifetime, but removing the Wait will not:
Lua:
function CreateExampleFloatingText()
    local texttag = CreateTextTag()
    SetTextTagTextBJ(texttag, "test", 10)
    SetTextTagPos(texttag, 0, 0, 0)
    SetTextTagColor(texttag, 255, 207, 0, 0)
    --So far so good. The texttag would be successfully created, if we stopped at this point.
    --Now we add a small wait to make SetTextTagPermanent work. Removing the wait would make the texttag disappear.
    TriggerSleepAction(0.025) --TriggerSleepAction used for example purposes for code simplicity. Would normally use timers.
    SetTextTagPermanent(texttag, false) --Will make Texttag disappear, when the wait above is not present
    SetTextTagLifespan(texttag, 2.00)
    SetTextTagVelocityBJ(texttag, 64, 90)
end

Reason seems to be that SetTextTagPermanent makes the texttag disappear, when you call it too early after creation.
Note that even a zero-wait is too early. You need to wait at least ~0.025s to make it work (tested with timers).
Strangely enough, I couldn't reproduce the bug in GUI, so I might just have used some native wrong.

Is this a known thing? What am I doing wrong?

Best regards,
Eikonium
 
Last edited:

Uncle

Warcraft Moderator
Level 42
Joined
Aug 10, 2018
Messages
4,198
You're going to laugh at this one. The issue is that you're setting the Alpha of the text to 0 (completely transparent).

It works fine otherwise :p
Lua:
function CreateExampleFloatingText()
    local texttag = CreateTextTag()
    SetTextTagTextBJ(texttag, "test", 10)
    SetTextTagPos(texttag, 0, 0, 0)
    --SetTextTagColor(texttag, 255, 207, 0, 0) -- red, green, blue, alpha
    SetTextTagPermanent(texttag, false)
    SetTextTagLifespan(texttag, 2.00)
    SetTextTagVelocityBJ(texttag, 64, 90)
end
 
Level 20
Joined
Nov 18, 2012
Messages
1,621
When using SetTextTagColour, the last parameter is transparency, and you need to set it to 255. Blizzard.j's warper makes it the inverse.
1659806183420.png


Edit: Uncle is travelling at light speed!
 
Level 15
Joined
Jul 10, 2009
Messages
347
Ha, good catch, thanks guys!
As Wrda suggested, I came from the Bj and didn't see it got inversed :)

This was a hard one to see for me during debugging, because alpha=0 actually creates a visible texttag, when you don't apply SetTextTagPermanent, which is why I thought it would be one to blame:

Lua:
function CreateExampleFloatingText()
    local texttag = CreateTextTag()
    SetTextTagTextBJ(texttag, "test", 10)
    SetTextTagPos(texttag, 0, 0, 0)
    SetTextTagColor(texttag, 255, 207, 0, 0) --alpha set to 0, but texttag is visible. Other colors are applied properly.
end

Why is that? :)

Also, why would the texttag remain visible after calling SetTextTagPermanent after delay, but not after calling it immediately?
 
Level 18
Joined
Jun 26, 2020
Messages
1,455
I think it has to do because the texttags has by default 0 lifespan, and then if the life of a texttag is greater than the lifespan, it disappears (that would be the reason that only happens after 0.025s, because it needs to check first).
So I would recommend first set the lifespan and then set the permanence to false.
 
Last edited:

Uncle

Warcraft Moderator
Level 42
Joined
Aug 10, 2018
Messages
4,198
I think it has to do because the texttags has by default 0 lifespan, and then if the life of a texttag is greater than the lifespan, it disappears (that would be the reason that only happens after 0.025s, because it needs to check first).
So I would recommend first set the lifespan and then set the permanence to false.
That's what I thought but the code I posted earlier works fine. It's really weird...
 
Level 15
Joined
Jul 10, 2009
Messages
347
So I would recommend first set the lifespan and then set the permanence to false.
I've tested so, but swapping the two doesn't seem to change anything. Still, it was a good theory :)



After thinking more about it, I'd suggest that we simply can't change the alpha value of a permanent text tag. No matter which alpha-value you choose, the text tag will always remain 100%-visible. I knew this was true for lifespan and velocity (can't be used for permanent text tags), but I wasn't aware of the same logic applying to alpha.

First removing permanence and changing alpha afterwards works properly. Order of calls apparently doesn't matter, so first changing alpha and afterwards removing permanence (but in the same tick) works just as fine -> alpha correctly applied.
I suppose the alpha change has an internal delay of ~ one game tick to apply, so setting the alpha, waiting a timeframe shorter than one tick (e.g. 0.01s) and then removing permanence would still properly apply the new alpha (i.e. permanence already removed, when alpha finally applies).
Waiting longer than a game tick however would apply the color, when the text tag is still permanent (so alpha stays at 100%). This would finally explain the behaviour I've observed in my initial post:

Lua:
--This is what might have happened
function CreateExampleFloatingText()
    --First create the text tag
    local texttag = CreateTextTag()
    SetTextTagTextBJ(texttag, "test", 10)
    SetTextTagPos(texttag, 0, 0, 0)
    --Now we change the alpha value, but the call needs some time to take effect. Text tag is currently permanent.
    SetTextTagColor(texttag, 255, 207, 0, 0)
    --Wait long enough, so the color change apply, when the text tag is still permanent - consequently the alpha change won't take effect
    TriggerSleepAction(0.025)
    --Now we make the text tag permanent, but it's too late (color already applied, alpha change already vanished)
    SetTextTagPermanent(texttag, false)
    SetTextTagLifespan(texttag, 2.00)
    SetTextTagVelocityBJ(texttag, 64, 90)
end
That's all guessed of course, but sounds good to me :D
 
Top