• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[vJASS] Issues getting Floating Text to Show

Status
Not open for further replies.
Basically, this should put a text above a units head telling the players how many bullets is left in their clip, how many bullets they have, ect. But it does not display it. The trigger runs as it shows all the "Parts" in chat correctly. Yet it displays nothing.

Globals:
JASS:
globals
integer array PlayerClips[12][5] ///1 = clipsize, 2 = currently in clip, 3= bullets overall, 4 = bulletpertick, 5 = tick interval in seconds/10
texttag array FloatText[12][1] //1 = clip
endglobals

The function that should show the text:
JASS:
function CreateBullets takes nothing returns nothing
    local integer i = 0
    
        call DisplayTextToForce( GetPlayersAll(), "Part 2" )    
     
    loop
            call DisplayTextToForce( GetPlayersAll(), "Part 3" ) 
        set FloatText[i][1] = CreateTextTag()
        call SetTextTagText(FloatText[i][1], ConcecrateAmmo(i), (15. * 0.023 * 10.0)) //ConcecrateAmmo(i)  /PlayerClips[i][1]
        call SetTextTagPosUnit(FloatText[i][1], udg_PlayerUnit[i+1], 60.0)
    
        //if GetLocalPlayer() == Player(i) then
            call SetTextTagVisibility(FloatText[i][1], true)
        //endif
    
            call DisplayTextToForce( GetPlayersAll(), "Part 4" ) //test
    
        exitwhen i == 11
        set i = i + 1
    endloop

endfunction



ConcerateAmmor and GetIS (Should not relevant to the problem)
JASS:
function GetIs takes integer ClipSize, integer remainingBullets returns string
local string s = ""
local integer i = 0
local integer o = remainingBullets

loop
    
    if o > 0 then
        set s = s + "I"
    else
        set s = s + "|c00808080I|r"
    endif
    
    
    
    exitwhen i == ClipSize
    set i = i + 1
    set o = o -1
    
endloop

return s
endfunction

function ConcecrateAmmo takes integer id returns string
local string I = GetIs(PlayerClips[id][1], PlayerClips[id][2])
local string para = " (" + I2S(PlayerClips[id][2]) + "/" + I2S(PlayerClips[id][3]) + ")"



return "|cffffcc00[|r" + I + "|cffffcc00]|r" + para
endfunction

Setup (Just test values for the system, shouldn't be relevant either)
JASS:
function Trig_Untitled_Trigger_002_Actions takes nothing returns nothing
    set udg_PlayerUnit[0] = gg_unit_hfoo_0001
    set PlayerClips[0][1] = 4
    set PlayerClips[0][2] = 2
    set PlayerClips[0][3] = 75
    set PlayerClips[0][4] = 1
    set PlayerClips[0][5] = 10
endfunction
 
EDIT: You're using JNGP (or JassHelper) right? That's the only way multidimensional arrays will work ( like FloatText[i][1]) without explicitly simulating it

Try this out and make sure the unit / string isn't null.

JASS:
function CreateBullets takes nothing returns nothing
    local integer i = 0
     
    loop
        call BJDebugMsg("Unit: " + I2S(GetHandleId(udg_PlayerUnit[i+1])))
        call BJDebugMsg("STR: " + ConcecrateAmmo(i))
        
        set FloatText[i][1] = CreateTextTag()
        call SetTextTagText(FloatText[i][1], ConcecrateAmmo(i), (15. * 0.023 * 10.0)) //ConcecrateAmmo(i)  /PlayerClips[i][1]
        call SetTextTagPosUnit(FloatText[i][1], udg_PlayerUnit[i+1], 60.0)
        call SetTextTagColor(tt, 255, 255, 255, 0)
        
        //if GetLocalPlayer() == Player(i) then
            call SetTextTagVisibility(FloatText[i][1], true)
        //endif
    
        exitwhen i == 11
        
        set i = i + 1
    endloop

endfunction
I also set the color/transparency. I'm not sure if that's required or not, I haven't dealt with texttags too much.
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
"call SetTextTagColor(tt, 255, 255, 255, 0)"
Wont that make it invisible?

Your size calculation is wrong.
You have to divide it by 10 or multiply it by 0.1.

I also use these methods:
JASS:
        call SetTextTagPermanent(tt, false)
        call SetTextTagLifespan(tt, 1.3)
        call SetTextTagFadepoint(tt, 0.9)

Why is your text size so high?
call SetTextTagText(FloatText[i][1], ConcecrateAmmo(i), (15. * 0.023 * 10.0)) Perhaps that's the problem? Try 0.023 only and see if it will display.

JASS:
function TextTagSize2Height takes real size returns real
    return size * 0.023 / 10
endfunction

function SetTextTagTextBJ takes texttag tt, string s, real size returns nothing
    local real textHeight = TextTagSize2Height(size)

    call SetTextTagText(tt, s, textHeight)
endfunction
 
Level 14
Joined
Jan 16, 2009
Messages
716
It's pretty tricky to center the text as it is dependent of the camera distance and the font size. Though, if you are using default camera distance and font size, there is a formula to center texttags in a Cohadar's texttags library.
 
Level 23
Joined
Feb 6, 2014
Messages
2,466
@Wietlol, let's play spot the difference ;) (Hint: Look at the operation)
call SetTextTagText(FloatText[i][1], ConcecrateAmmo(i), (15. * 0.023 * 10.0))

JASS:
function TextTagSize2Height takes real size returns real
    return size * 0.023 / 10
endfunction

function SetTextTagTextBJ takes texttag tt, string s, real size returns nothing
    local real textHeight = TextTagSize2Height(size)

    call SetTextTagText(tt, s, textHeight)
endfunction


Is there any good way to center the text? Or do I have to calculate the middle manually and move it accordingly?
Didn't know any native that centers it, I recalled doing it manually which is possible because you can get the string length via StringLength though each character has different sizes (e.g. 'l' and 'x') so it won't be perfect. You also have to calibrate it based on the text size.
 
Sadly I calculate font size on string length currently, which is pretty necessary since the textag gets pretty long.

My current idea was pretty much to do something like:
(string length / 2) * (distance * font size )

Where "distance" is a about the distance of a single letter. Probably about 12.8 or something.

This is obviously not precise, since not all letters has the same length in wc3 font. But should get somewhat close to the middle still? Just move the font loc / (x,y) accordingly.
 
Level 23
Joined
Feb 6, 2014
Messages
2,466
My current idea was pretty much to do something like:
(string length / 2) * (distance * font size )

That would work if xy coordinate distance is proportional to the font size. Unfortunately I don't know if it is proportional or not, but if it is, you would probably need another variable in the equation for the constant k of linear proportion. Something like:

(string length/2)*k*(distance*font size)
 
(string length/2)*k*(distance*font size)

Yeah, "K" ended up being around "35". That was not the result of any logic, but testing. It strangely works better with long strings than short strings. Anyway, good enough for my needs.

Edit: Yeah, panning the camera obviously also messes with the centring. But, me, looks good enough still.
 
Status
Not open for further replies.
Top