Warcraft III resources & community, 2003–2006 · archived

Help with this code - Game crashes!!

32 posts
#16
han... :P
don't know hot to use well yet
#17
Practice Makes Perfect :D
#18
Now I am trying to understand that huge code... I can't use handlers!! I don't know how xD

Can you give me an example of how to store a local unit? The function SetHandleBoolean takes a handle, a string and a value. What shoul I put as the handle?
#19
what youre storing it ON

(most likely your timer)

to store a unit, or any other HANDLE (anything thats not an int, real, boolean, code, or string), use SetHandleHandle, but you have to individually get them (eg. GetHandleUnit, GetHandleGroup)
#20
Should this work?
It's supposed to create a kind of Wisp (a counter) at the position of the KillingUnit and store the group of Wisps as a handle attached to Kinara (the hero's name), but not if the number of Counters in the group is greater or equal to the level of the ability x2.

It seems to only create the unit...
(cut a lot of the code, but I think it's not important)


function CounterUp takes nothing returns nothing
    local unit Kinara = GetKillingUnit()
    local unit Kill = GetDyingUnit()
    local group G = GetHandleGroup(Kinara, "Counters")
    local integer Level = GetUnitAbilityLevelSwapped( 'A019', Kinara )
    local integer Counters = CountUnitsInGroup(G)

    if (Counters < Level * 2) and (IsUnitEnemy(Kill, GetOwningPlayer(Kinara)) == true) and (IsUnitType(Kill, UNIT_TYPE_STRUCTURE) == false) and (IsUnitType(Kill, UNIT_TYPE_ANCIENT) == false) and GetUnitTypeId(Kinara) == 'N002' then
        set Counters = Counters + 1
        set Ang = I2R(360 / Counters)
        call CreateUnit(GetOwningPlayer(Kinara), 'u00C', GetLocationX(GetUnitLoc(Kinara)), GetLocationY(GetUnitLoc(Kinara)), Ang)
        call GroupAddUnitSimple(GetLastCreatedUnit(), G)
        call SetHandleHandle( Kinara, "Counters", G )
    endif
    set G = null
    set Kinara = null
    set Kill = null
endfunction


Am I deluded or Handle Vars are like Attached Variables?
#21
Excuse me while I maim you *jk*

Anyways, you have to have stored the group at some point, so the first time it will return null, which is not good

About attachable vars, they were BASED off the handle vars.

and, here we go, a few code review thingees

GetDyingUnit = bleh. Use GetTriggerUnit

and that abominably long condition can be shortened to this

 if Counters < Level * 2 and IsUnitEnemy(Kill, GetOwningPlayer(Kinara)) and GetUnitTypeId(Kinara) == 'N002' and not (IsUnitType(Kill, UNIT_TYPE_STRUCTURE) or IsUnitType(Kill, UNIT_TYPE_ANCIENT))
#22
Even when you laugh at me I find something inside me that makes me laugh too (I know I'm stupid)

I think I've bothered you too much already.
#23
Jeez, continue, i LIKE answering questions like this :D

Its good to see someone else learning something new.
#24
Ok, if you are saying that... :P

You said that I must initialize it. Do I do it with this?
call SetHandleHandle(Kinara, "Counters", null)

And, just to make things clear, is the value of the handle stored with Kinara and "Counters" as references?

Really thanks for your time ^^
I need to learn this...
Hossomi
#25
nononoon

i meant

at the START OF THE GAME

do this

set udg_cache = InitGameCache( "jasslocalvars.w3v" )
#26
Uh.. Sorry.. I did that xP

But.. about that code I posted above, should it work?
#27
lol...

no.

A) atleast as far as i can see, you never created the group.

B) CreateUnit does not return GetLastCreatedUnit(). You'll have to set [variable] = CreateUnit( blah )

C) fix that GroupAddUnitSimple call :P. It should just be GroupAddUnit

D) Lookit what I said in the post after that code

E) Replace GetUnitAbilityLevelSwapped with GetUnitAbilityLevel

F) the variable Ang that you're using was never defined.
#28
:shock: Yang bless me...

A. Create the group, you mean, CreateGroup()? (ohh ignorance)
B. Fixed
C. Fixed
D. Read and fixed
E. Fixed
F. In fact, it was, but I cut it by accident xD

Now I wrote an If that Set G = CreateGroup() if G == null, as there was in KaTTaNa's example...

It still doesn't work, but I'll try more tomorrow morning 'cause now I need to sleep... That's what night serves for...

Again and again, thanks PurplePoot
Hossomi
#29
If you post the fixed code, then I'll have another look.
#30
Oh sorry, there's some time I don't enter here due to a lack of time ^^'

function CounterUp takes nothing returns nothing  local unit Kinara = GetKillingUnit()
local unit Kill = GetTriggerUnit()
local unit u
local group G = GetHandleGroup(Kinara, "Counters")
local integer Level = GetUnitAbilityLevel( Kinara, 'A019' )
local integer Counters = CountUnitsInGroup(G)
local real Ang = 0
if (Counters < Level * 2) and (IsUnitEnemy(Kill, GetOwningPlayer(Kinara)) == true) and GetUnitTypeId(Kinara) == 'N002' and not (IsUnitType(Kill, UNIT_TYPE_STRUCTURE) == false) or (IsUnitType(Kill, UNIT_TYPE_ANCIENT) == false) then 
if G == null then
set G = CreateGroup()
endif
set Counters = Counters + 1
set Ang = I2R(360 / Counters)
set u = CreateUnit(GetOwningPlayer(Kinara), 'u00C', GetLocationX(GetUnitLoc(Kinara)), GetLocationY(GetUnitLoc(Kinara)), Ang)
call GroupAddUnit(G, u)
call SetHandleHandle( Kinara, "Counters", G )
endif
set G = null
set Kinara = null
set Kill = null
endfunction


I think I fixed everything here.
May I change CreateUnit to CreateNUnitsAtLoc? I saw somewhere that this was buggy..