• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Texttags

Status
Not open for further replies.
Level 15
Joined
Nov 30, 2007
Messages
1,202
I tried to create texttags, but they dont apear on map.

JASS:
        set tt = CreateTextTag()
        call SetTextTagText(tt, CityName[i], 12) 
        call SetTextTagPosUnit(tt, City[i], 50)
        call SetTextTagColor(tt, 100, 100, 100, 0)

If I manage to implement that I want to add a command to show or hide them for that player, so I guess I wont be using local texttags. But how would that be done? How to hide a texttag or show it for a triggering player.
 
Did you try adding call SetTextTagVisibility(tt, true)?

As for your second question, it is possible to create texttags for specific players without desyncs, e.g.:
JASS:
if GetLocalPlayer() == GetTriggerPlayer() then
    set tt = CreateTextTag()
endif

(it isn't an agent) But if you wish to only modify the visibility for a particular player, you can do it like so:
JASS:
if GetLocalPlayer() == GetTriggerPlayer() then
    call SetTextTagVisibility(tt, true)
endif

// or... 
call SetTextTagVisibility(tt, GetLocalPlayer() == GetTriggerPlayer())
 
Oh I see the issue. Take a look at the BJ:
JASS:
function CreateTextTagUnitBJ takes string s, unit whichUnit, real zOffset, real size, real red, real green, real blue, real transparency returns texttag
    set bj_lastCreatedTextTag = CreateTextTag()
    call SetTextTagTextBJ(bj_lastCreatedTextTag, s, size)
    call SetTextTagPosUnitBJ(bj_lastCreatedTextTag, whichUnit, zOffset)
    call SetTextTagColorBJ(bj_lastCreatedTextTag, red, green, blue, transparency)

    return bj_lastCreatedTextTag
endfunction

This passes the info on to other BJ's. When you're using the natives, you have to be sure to pass it the correct information in the proper form. Generally, natives use 0-255 for red/green/blue/alpha instead of percentages. And the texttag size differs. If you wanted an equivalent set of actions, you would actually use:
JASS:
        set tt = CreateTextTag()
        call SetTextTagText(tt, CityName[i], 12 * 0.023 / 10) // see TextTagSize2Height
        call SetTextTagPosUnit(tt, City[i], 50)
        call SetTextTagColor(tt, 255, 255, 0, 255) // red, green, blue, alpha

Unlike the BJ's, most natives will ask for an alpha value instead of a transparency percentage. In GUI, you're used to 0% transparency meaning that the object will be shown. In JASS, that is equivalent to 255 alpha. 0 alpha would completely hide the object (just like 100% transparency). That likely explains why the texttag wasn't showing up.

As for the texttag size, Blizzard made a function to translate standard font sizes (such as 12) into texttag sizes for the native. It is TextTagSize2Height. It is a weird function, but if you forget to use it on your input for the native, you'll likely end up with a massive texttag (or it won't display at all). Try testing out the code I posted above.
 
Level 15
Joined
Nov 30, 2007
Messages
1,202
Ah great works now!

For the other part:

JASS:
function ShowHideLabel takes nothing returns nothing
    local integer pID = GetPlayerId(GetTriggerPlayer())
    local integer i = 0
    if (DisplayCityName[pID] == true) then
        set DisplayCityName[pID] = false 
    else
        set DisplayCityName[pID] = true
    endif
    if (GetLocalPlayer() == Player(pID)) then
        loop
            exitwhen CityName[i] == null
            call SetTextTagVisibility(CityLabel[i], DisplayCityName[pID]) 
            set i = i + 1
        endloop
    endif

endfunction
 
Last edited:
@PurgeandFire, would not creating them localy could cause desync? I'm used to show only localy or to set the output string only localy.

If you create/destroy an agent locally, it will desync. Agents are defined by Blizzard as "reference counted objects". However, there are some handles that aren't agents, such as texttags, weathereffects, lightning, etc. Those ones are likely handled differently internally, because they can be created locally without disconnecting the players.

For a more technical reason: all agents are on a shared handle stack. When an agent is created or destroyed locally, Warcraft 3 likely performs a check on the handle stack and makes sure that it is consistent on each client. If the slot 1048700 is taken for Player 1, but not any of the other players, the client will just think "wtf?" and disconnect players.

As for non-agent handles, they have their own stacks (usually values staring from 0 or 100). Warcraft 3 probably does not check whether those are in sync (especially since all those types are usually visual only and do not affect gameplay).

Anyway, in most cases, it is still a better habit to just locally hide/display handles, regardless of their type. However, texttags are limited to 100 simultaneously on the map. To avoid that limit, you can locally create them (to get a limit of 100 simultaneous texttags per player). But if you aren't going to hit that limit, I would just modify the visibility locally. :)
 
Status
Not open for further replies.
Top