HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Struct Problems

03-07-2008, 12:58 PM#1
Tiku
Hello, Recently i decided to learn structs, thinking that they werent to tuff, since its just a replacement of Handle Vars, and they are faster right?
Well anyways, i tried making a simple spell using structs instead of Handle Vars... but i encountered a few problems ingame....

I use Jass NewGen Pack v4c

Here is the Trigger:
Collapse JASS:
struct netdata
    unit u
    unit net
    real time
endstruct    

constant function CasterId takes nothing returns integer
    return 'n001'
endfunction

constant function NetSfx takes nothing returns integer
    return 'o000'
endfunction

constant function Net_CasterAbilityId takes nothing returns integer
    return 'A001'
endfunction

function Trig_Net_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A000'
endfunction

function Net_Check takes nothing returns boolean
    return IsUnitAliveBJ(GetFilterUnit()) == true
endfunction

function Net_Timer takes nothing returns nothing
    local timer Nt = GetExpiredTimer()
    local netdata nd = netdata(GetHandleInt(Nt, "nd"))
    local unit u = nd.u
    local unit net = nd.net
    local real nx = GetUnitX(net)
    local real ny = GetUnitY(net)
    local boolexpr check = Condition(function Net_Check)
    local real time = nd.time
    local group g = CreateGroup()
    local unit dmg
    local unit caster
    local boolean flag = false
    
    set nd.time = time+0.3
    call GroupEnumUnitsInRange(g, nx, ny, 100.0, check)
    set dmg = FirstOfGroup(g)
    if dmg != null and time < 150.0 then
     call RemoveUnit(net)
     set caster = CreateUnit(GetOwningPlayer(u), CasterId(), nx, ny, 0.0)
     call UnitAddAbility(caster, Net_CasterAbilityId())
     call IssueTargetOrder(caster, "thunderbolt", dmg)
     call UnitApplyTimedLife(caster, 'B000', 2.0)
     set flag = true
    endif
    if time >= 150.0 or flag == true then
     call RemoveUnit(net)
     call FlushHandleLocals(Nt)
     call PauseTimer(Nt)
     call DestroyTimer(Nt)
    endif                                        
    
    call DestroyBoolExpr(check)
    set u = null
    set net = null
    set check = null
    set caster = null
    set dmg = null 
endfunction

function Trig_Net_Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local location loc = GetSpellTargetLoc()
    local real lx = GetLocationX(loc)
    local real ly = GetLocationY(loc)
    local netdata nd = netdata.create()
    local unit net = CreateUnit(GetOwningPlayer(u), NetSfx(), lx, ly, 0.0)
    local timer Nt = CreateTimer()
    
    set nd.u = u
    set nd.net = net
    set nd.time = 0.0
    
    call SetHandleInt(Nt, "nd", nd)
    call TimerStart(Nt, 0.03, true, function Net_Timer)
    
    call RemoveLocation(loc)
    call netdata.destroy(nd)
    set u = null
    set loc = null
    set net = null
endfunction

//===========================================================================
function InitTrig_Net takes nothing returns nothing
    local unit NtU = CreateUnit(Player(13), 'hpea', 0.0, 0.0, 0.0)
    call UnitAddAbility(NtU, Net_CasterAbilityId())
    call RemoveUnit(NtU)
    set NtU = null
    set gg_trg_Net = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Net, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Net, Condition( function Trig_Net_Conditions ) )
    call TriggerAddAction( gg_trg_Net, function Trig_Net_Actions )
endfunction


Collapse JASS:
struct netdata
    unit u    // The Casting unit (The Troll)
    unit net  // The actual net
    real time // The "Timer" to turn off the spell
endstruct  

I also recorded ingame to show you guys what i mean.

Sorry for the bad Quality
Struct Problem:



Okay the problems are:
  • There is a noticeable amount of delay before the ogre triggers spell to go off.
  • It isnt "Multi-Instanceanble" as in i can't lay 2 nets down, or the last one will be canceled out.

If you look at the .gif then you will see about a 1-1.5sec delay when the ogre steps over the net for the trigger to stun it. Also i tried using ensnare instead of storm bolt, it worked but it had the same delay... and then if placed 2 nets down, and the first net was "turned off" and stood there, doing nothing...

I know there is a way to eliminate this delay, i've seen no delay in the spells that Pyrogasm's great spells... Also how would i use structs to be Multi-Instanceable...

I also attached the map, just in case you wanted to see the caster unit/spells and whatnot :)

Please Help me, and Thank you!
Attached Files
File type: w3xTrollandOgre.w3x (25.8 KB)
03-07-2008, 10:45 PM#2
Jazradel
Delay is probably caused by Stormbolt/Ensnare not your trigger.

Also, I suggest you look at the JassHelper readme for stuff about scopes.

You need to release structs once they're done, use
Collapse JASS:
nd.destroy()

You don't need to destroy boolexprs, they're only ever created once and then stored.

You're also creating unnecessary variables.
Collapse JASS:
    local netdata nd = netdata.create()
    local unit net = CreateUnit(GetOwningPlayer(u), NetSfx(), lx, ly, 0.0)
    set nd.u = u
Could be
Collapse JASS:
    local netdata nd = netdata.create()
    set nd.u = CreateUnit(GetOwningPlayer(u), NetSfx(), lx, ly, 0.0)

And for the way it only works with the last created one, I'm sure it's something obvious but try adding some debug messages.