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

[JASS] Help With Structs! Yargh!

Status
Not open for further replies.
Level 6
Joined
Aug 15, 2007
Messages
209
It just doesn't work v___v. Whenever I try to test this code with WE syntax, it disables all of them. Whenever I try without WE syntax, it loads WC, not WE, meaning there was an error in the script. It is supposed to create a struct when certain buildings are built, then access them and add units and handles.
Here is what I have...

The build trigger...
JASS:
function Trig_TowerBuild_Func001C takes nothing returns boolean
    if ( ( GetUnitTypeId(GetConstructedStructure()) == 'h002' ) ) or ( ( GetUnitTypeId(GetConstructedStructure()) == 'h004' ) ) or ( ( GetUnitTypeId(GetConstructedStructure()) == 'h001' ) )or ( ( GetUnitTypeId(GetConstructedStructure()) == 'h000' ) ) or ( ( GetUnitTypeId(GetConstructedStructure()) == 'h003' ) ) then
    return true
    else
    return false
    endif
endfunction

function Trig_TowerBuild_Actions takes nothing returns nothing
local unit s = GetConstructedStructure()
local towerinfo u = towerinfo.create()
call SetUnitUserData(s, u)
endfunction

//===========================================================================
function InitTrig_TowerBuild takes nothing returns nothing
    set gg_trg_TowerBuild = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_TowerBuild, EVENT_PLAYER_UNIT_CONSTRUCT_FINISH )
    call TriggerAddCondition( gg_trg_TowerBuild, Condition( function Trig_TowerBuild_Func001C ) )
    call TriggerAddAction( gg_trg_TowerBuild, function Trig_TowerBuild_Actions )
endfunction
The Struct
JASS:
struct towerinfo
unit array t[10]
unit u
lightning array l[10]
integer n = 0
method AddUnit takes unit add, unit trig returns nothing 
set this.n = this.n + 1
set this.t[this.n] = add
set this.l[this.n] = AddLightningEx( "CLPB", true, GetUnitX(trig),GetUnitY(trig), GetLocationZ(GetUnitLoc(trig)), GetUnitX(add),GetUnitY(add),GetLocationZ(GetUnitLoc(add)))
endmethod

method RemoveTransfer takes unit remove returns nothing
local integer c
set this.n = this.n - 1
loop
    set c = c + 1
    exitwhen remove == this.t[c]
endloop
call DestroyLightning(l[c])
loop
    set this.t[c] = this.t[c + 1]
    set this.l[c] = this.l[c + 1]
    set c = c + 1
    exitwhen this.t[c] == null
endloop
endmethod
endstruct
The Add Transfer Function
JASS:
function Trig_AddTransfer_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A002' 
endfunction

function Trig_AddTransfer_Actions takes nothing returns nothing
local towerinfo ti = GetUnitUserData(GetTriggerUnit())
call ti.AddUnit(GetSpellTargetUnit(),GetTriggerUnit())
endfunction

//===========================================================================
function InitTrig_AddTransfer takes nothing returns nothing
    set gg_trg_AddTransfer = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_AddTransfer, EVENT_PLAYER_UNIT_SPELL_CAST )
    call TriggerAddCondition( gg_trg_AddTransfer, Condition( function Trig_AddTransfer_Conditions ) )
    call TriggerAddAction( gg_trg_AddTransfer, function Trig_AddTransfer_Actions )
endfunction
The remove transfer...
JASS:
function Trig_RemoveTransfer_Conditions takes nothing returns boolean
   return GetSpellAbilityId() == 'A001' 
endfunction

function Trig_RemoveTransfer_Actions takes nothing returns nothing
local towerinfo ti = GetUnitUserData(GetTriggerUnit())
call ti.RemoveTransfer(GetSpellTargetUnit())
endfunction

//===========================================================================
function InitTrig_RemoveTransfer takes nothing returns nothing
    set gg_trg_RemoveTransfer = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_RemoveTransfer, EVENT_PLAYER_UNIT_SPELL_CAST )
    call TriggerAddCondition( gg_trg_RemoveTransfer, Condition( function Trig_RemoveTransfer_Conditions ) )
    call TriggerAddAction( gg_trg_RemoveTransfer, function Trig_RemoveTransfer_Actions )
endfunction

The add function puts a handle and unit in the next spot in the arrays, while the remove finds the unit in the array, and replaces all the units above it so space is saved. I think though, that the problem is somewhere in the creation of the struct. Any help is appreciated. THanks.
 
Level 11
Joined
Aug 25, 2006
Messages
971
Are you sure you turned off normal world editor's syntax check, and enabled jasshelper? Do you have the latest version of vJass?

The only error I got when I compiled all that code was:
JASS:
call DestroyLightning(l[c])
You never said what the variable 'l' is. If thats a global, (The only globals I could guess were the trigger globals) then you have no syntax errors.
 
Level 11
Joined
Feb 18, 2004
Messages
394
It's a member of the towerinfo struct, so all you need to add is this.l[c] or simply .l[c]

the abbriviated form is far from consise and well written, unlike the rest of JASS. For consitency and comprehendability, i would recomend always using the "this" keyword. "0." for a real type value is minutely faster than "0.0" or even "0", but "0.0" is still more clear and consise.

(note: me = drunk, so don't trust at the very least grammar and spelling)
 
Status
Not open for further replies.
Top