• 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.

Problem with Handle Var

Status
Not open for further replies.
Hello everyone!
I've been trying to make a spell that increases level with each attack. Ya, it's easy so far, but I also want to create Wisps around the hero for each level.

I'm using KaTTaNa's Local Handle Variables. I'm having trouble to keep the Group in the Attacker:

JASS:
    local group G = GetHandleGroup(Caster, "Group")
    local integer Counters = GetHandleInt(Caster, "Counters")
    local unit U
    set Counters = Counters + 1

    if G == null then
        set G = CreateGroup()
    endif

    set U = CreateUnit(GetOwningPlayer(Caster), 'e001', GetUnitX(Caster), GetUnitY(Caster), 72 * I)
    call GroupAddUnit(G, U)
    call SetHandleHandle(Caster, "Group", G)
    call SetHandleInt(Caster, "Counters", Counters)
    set G = null
    set U = null

G = Group of Wisps
Counters = Number of Wisps
e001 = Wisp

When G is null, the unit is added normally, but from the second attack on, the group has no units. The variable Counters is kept normally.

I've been trying this spell since a year ago =/
Thanks for your time
Hossomi
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
First note: you don't need a unit variable.

Second note: handles are only referenced with the Handle Vars, thus you shouldn't need to reattach them

Third note: the reference shouldn't asplode unless you run FlushHandleLocals() or just attach 'null' to "Group"

Fourth note: it's more efficient to store g as CreateGroup() when you create the group rather than running an if-statement every interval.

The code should come out something like this (assuming G was also attached as CreateGroup(), not null)

JASS:
call GroupAddUnit(GetHandleGroup(Caster,"Group"),CreateUnit(GetOwningPlayer(Caster),'e001',GetUnitX(Caster),GetUnitY(Caster),72*I))
call SetHandleInt(Caster,"Counters",GetHandleInt(Caster,"Counters")+1)

(this assumes you don't reuse Counters in that execution. If you do, you can do the following instead of the above Counters line)

JASS:
local integer Counters = GetHandleInt(Caster,"Counters")+1
call SetHandleInt(Caster,"Counters",Counters)
//do other stuff with Counters here

EDIT: Please post in the JASS forum next time you have a JASS question ><. It helps keep the forums to order, and you'll also probably get more help there
 
I guess you are getting tired of trying to help me xD

I'll try everything you said (you answered other three questions I was going to ask at once =P)

Indeed, thank you for helping me since wc3search!
Sorry for the inconvenience =P

EDIT:

Oh God... Here's the whole function:
JASS:
function AddCounter takes nothing returns nothing
    local unit Caster = GetEventDamageSource()
    local integer Counters = GetHandleInt(Caster, "Counters") + 1

    call DestroyTrigger(GetTriggeringTrigger())
    call BJDebugMsg(I2S(Counters)) // Shows Counters, which is alright

    if Counters > 5 then
        return
    endif

    call GroupAddUnit(GetHandleGroup(Caster, "Group"), CreateUnit(... 'e001' ...))
    call BJDebugMsg(I2S(CountUnitsInGroup(GetHandleGroup(Caster, "Group")))) //Shows always 0
    call SetHandleInt(Caster, "Counters", Counters)
    set Caster = null
endfunction

This way it seems that the units are never added to the group. However, why should the "GroupAddUnit" be not working?

If I write this way...
JASS:
function AddCounter takes nothing returns nothing
    local unit Caster = GetEventDamageSource()
    local integer Counters = GetHandleInt(Caster, "Counters") + 1

    call DestroyTrigger(GetTriggeringTrigger())
    call BJDebugMsg(I2S(Counters)) // Shows Counters, which is alright

    if Counters > 5 then
        return
    endif

    if GetHandleGroup(Caster, "Group") == null then
        call SetHandleHandle(Caster, "Group", CreateGroup())
    endif

    call GroupAddUnit(GetHandleGroup(Caster, "Group"), CreateUnit(... 'e001' ...))
    call BJDebugMsg(I2S(CountUnitsInGroup(GetHandleGroup(Caster, "Group")))) //Shows 1 for the first attack, then 0
    call SetHandleInt(Caster, "Counters", Counters)
    set Caster = null
endfunction

There will be 1 unit in the group, but from the second attack on, it seems that the group has not been initialized, because the DebugMsg will return 0. Why did the previous unit disappear?

Thanks for your time again... Actually you're losing your patience, I think...
 
Last edited:
Here's the initial function:
JASS:
function Counters takes nothing returns nothing
    local trigger T = CreateTrigger()
    call TriggerAddAction( T, function AddCounter )
    call TriggerRegisterUnitEvent( T, GetTriggerUnit(), EVENT_UNIT_DAMAGED )
    set T = null
endfunction

What gave you that impression? ><

It wasn't you, but I hate to keep asking the same thing for so much time =/
At wc3search my topic filled three pages with your posts and mine xD
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
As I said, with my way, that should be

JASS:
function Counters takes nothing returns nothing
    local trigger T = CreateTrigger()
    call TriggerRegisterUnitEvent(T,GetTriggerUnit(),EVENT_UNIT_DAMAGED)
    call TriggerAddAction(T,function AddCounter)
    call SetHandleHandle(T,"Group",CreateGroup()
    set T = null
endfunction
Since mine skipped out on the if/then
 
I did as you said but, no use =/
I think you meant call SetHandleHandle(GetAttacker(), "Group", CreateGroup()) or am I wrong? Because I don't see why to do this to the trigger, since it will be destroyed =P

Greatest EDIT of my life:
MAN IT WORKS =D
I don't even know what I changed xD
But it works =D

(Thanks³)² PurplePoot =P
Yin-Yang will protect you for your life and eternity!
 
Last edited:
Status
Not open for further replies.
Top