HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Expiration Timer with Floating text in JASS help

05-17-2006, 07:09 PM#1
The)TideHunter(
Ok, this started off with me helping somebody.
But in the end, i actually need some help lol. This code isent working the way it should do.

I have 1 variable, a gamecache

Collapse JASS:
gamecache         udg_GC          = null

This code as basics:

Collapse JASS:
function GC takes nothing returns gamecache
    if(udg_GC == null) then
        call FlushGameCache(InitGameCache("GC"))
        set udg_GC = InitGameCache("GC")
    endif
    return udg_GC
endfunction

// Handle Variables
function H2I takes handle H returns integer
    return H
    return 0
endfunction

function I2Unit takes integer I returns unit
    return I
    return null
endfunction

function I2TextTag takes integer I returns texttag
    return I
    return null
endfunction

And this is the real code.
Its not killing the unit or making the text.
I have tested by adding messages to see whats doing what, it runs fine.
But its just not setting target to the stored unit.

Here it is:

Collapse JASS:
//**********
// AddUnitDeath_Child(unit whichUnit, integer SecsToLive)
//
function AddUnitDeath_Adult takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local unit target = I2Unit(GetStoredInteger(GC(), I2S(H2I(t)), "AddUnitDeath_Unit"))
    local integer TimeLeft = GetStoredInteger(GC(), I2S(H2I(t)), "AddUnitDeath_LeftToLive")
    local texttag oldTag = I2TextTag(GetStoredInteger(GC(), I2S(H2I(t)), "AddUnitDeath_CurrentTag"))
    local texttag newTag = CreateTextTag()
    if(TimeLeft == 0) then
        call KillUnit(target)
        call FlushStoredMission(GC(), I2S(H2I(t)))
        call DestroyTextTag(newTag)
        call DestroyTimer(t)
        set newTag = null
        set t = null
    else
        call SetTextTagText(newTag, I2S(TimeLeft), 50.)
        call SetTextTagPosUnit(newTag, target, 50.) 
        call SetTextTagColor(newTag, 100, 100, 100, 0) 
        call StoreInteger(GC(), I2S(H2I(t)), "AddUnitDeath_LeftToLive", TimeLeft - 1)
        call StoreInteger(GC(), I2S(H2I(t)), "AddUnitDeath_CurrentTag", H2I(newTag))
        call TimerStart(t, 1., false, function AddUnitDeath_Adult)
    endif
    call DestroyTextTag(oldTag)
    set oldTag = null
    set TimeLeft = 0         
endfunction

function AddUnitDeath_Child takes unit whichUnit, integer timeToLive returns nothing
    local timer t = CreateTimer()
    call StoreInteger(GC(), I2S(H2I(t)), "AddUnitDeath_Unit", H2I(GetSpellTargetUnit()))
    call StoreInteger(GC(), I2S(H2I(t)), "AddUnitDeath_LeftToLive", timeToLive)
    call TimerStart(t, 1., false, function AddUnitDeath_Adult)
endfunction

Any help will be much appreicated

EDIT: Problem solved, i used GetSpellTargetUnit() instead of whichUnit.
1 more problem though, its still not creating the text. Any reasons why?
05-17-2006, 07:42 PM#2
Captain Griffen
You don't null newTag or target local variables if it uses the 'else'.

Should TimeLeft = 0 be TimeLeft = TimeLeft - 1?

call SetTextTagColor(newTag, 100, 100, 100, 0)

Not sure, but that may be your problem. Don't the non-BJs use the opposite way round for transparency (so 0% = full transparent)?
05-17-2006, 08:13 PM#3
The)TideHunter(
I dont null newTag or the timer in the else because im going to use them there.
Theres no point in nulling them to un-null them again.

TimeLeft is fine, i use set it to TimeLeft - 1 in this line:

Collapse JASS:
call StoreInteger(GC(), I2S(H2I(t)), "AddUnitDeath_LeftToLive", TimeLeft - 1)

And no, it isent reverse unfortunatly:

Collapse JASS:
function SetTextTagColorBJ takes texttag tt, real red, real green, real blue, real transparency returns nothing
    call SetTextTagColor(tt, PercentTo255(red), PercentTo255(green), PercentTo255(blue), PercentTo255(100.0-transparency))
endfunction
05-17-2006, 09:35 PM#4
Captain Griffen
You don't null those handle locals in that function. That is a leak. They are recreated when the function is run again by the timer.

call SetTextTagColor(newTag, 100, 100, 100, 0)

Change to:

call SetTextTagColor(newTag, 255, 255, 255, 255)
05-18-2006, 10:59 AM#5
The)TideHunter(
The newly created locals are just pointers i think, not sure.

call SetTextTagColor(newTag, 100, 100, 100, 0) is correct

call SetTextTagColor(newTag, 255, 255, 255, 255) is incorrect

the function

Collapse JASS:
SetTextTagColor

takes percentages as integers, not colours as reals.
100 is equal to 255
50 is equal to 127.5
10 is equal to 25.5
0 is equal to 0
05-18-2006, 12:53 PM#6
blu_da_noob
Quote:
call SetTextTagColor(newTag, 255, 255, 255, 255) is incorrect

That is the correct one. Notice how the BJ one has a function called 'PercentTo255'? That is converting the % you enter in the BJ function to an integer with 100% = 255.
05-18-2006, 02:43 PM#7
shadow1500
and
Collapse JASS:
PercentTo255(100.0-transparency)
is reverse, it takes transparency, reverses it, and then converts it to 255 format, so "PercentTo255(100-0)" is changed to 255 and "PercentTo255(100-100)" is changed to 0.
05-18-2006, 03:00 PM#8
The)TideHunter(
Damnit! i got myself mixed up.
I new the PercentTo255 exsisted, but i mixed up.
I said it the wrong way round lol.
Nvm, sorry for the mistake