tommerbob
Minecraft. :D
- Reaction score
- 110
Alright, I'm starting to get the hang of Jass, but structs are still eluding my understanding. I read the section on structs in the JassHelper manual (again), but I still don't know why I'm getting a syntax error:
The error says: "d is not of a type that allows . syntax"
The error is in the NearTrees function, specifically on this line:
I will post the whole code in case you need to see it:
Thanks for any help.
The error says: "d is not of a type that allows . syntax"
The error is in the NearTrees function, specifically on this line:
JASS:
set d.newx = GetUnitX(d.caster)
I will post the whole code in case you need to see it:
JASS:
scope Forestborn initializer init
globals
private constant integer SPELL_ID = 039;A000039; //rawcode of the Forestborn spell
private constant integer EVADE_ID = 039;A001039; //rawcode of the Evasion spell
private constant real INTERVAL = 0.5 //How often it checks for trees around caster
private constant real AOE = 150. //Max distance from a tree the caster can be
private constant real DURATION_BASE = 10. //Base duration of spell
private constant real DURATION_LVL = 2. //Added duration for each level of spell
private constant integer EVADE_BASE = 50 //Base chance for evasion. Set to 0 if you don't want the caster gaining evasion
private constant integer EVADE_LVL = 0 //Amount added to base evasion for each level of spell
private constant real HEAL_BASE = 6. //Base amount that the caster is healed for each second. Set this and HEAL_LVL to 0. if you don't want the caster healed
private constant real HEAL_LVL = 4. //Adds this amount to the base heal amount for each level of spell.
private constant boolean CAN_MOVE = true //Setting this to false will require the caster to remain stationary
private constant real MOVE_BASE = 20. //This is the move speed bonus the caster receives. Set to 0 if no bonus
private constant real MOVE_LVL = 0. //Amount added to base speed bonus for each level of spell
endglobals
private function Duration takes integer level returns real
return DURATION_BASE + DURATION_LVL * (level)
endfunction
private function Evasion takes integer level returns integer
return 1 + EVADE_BASE + EVADE_LVL * (level)
endfunction
private function Heal takes integer level returns real
return HEAL_BASE + HEAL_LVL * (level)
endfunction
private function MoveBonus takes integer level returns real
return MOVE_BASE + MOVE_LVL * (level)
endfunction
private struct data
unit caster
integer level
integer evasion
real heal
real movebonus
real time
real duration
real oldx
real oldy
real newx
real newy
timer t
static method create takes unit caster, real x, real y returns data
local data d = data.allocate()
set d.caster = caster
set d.level = GetUnitAbilityLevel(d.caster, SPELL_ID)
set d.time = 0.
set d.duration = Duration(d.caster, d.level)
set d.evasion = Evasion(d.caster, d.level)
set d.heal = Heal(d.caster, d.level)
set d.movebonus = MoveBonus(d.caster, d.level)
set d.oldx = x
set d.oldy = y
set d.t = NewTimer()
return d
endmethod
method onDestroy takes nothing returns nothing
set .caster = null
call ReleaseTimer(.t)
endmethod
endstruct
private function NearTrees takes nothing returns nothing
local destructable d = GetEnumDestructable()
if IsDestructableTree(d) then
if CAN_MOVE != true then //If the caster should not move, updates his location.
set d.newx = GetUnitX(d.caster)
set d.newy = GetUnitY(d.caster)
if d.newx != d.oldx or d.newy != d.oldy then
set d.oldx = GetUnitX(d.caster)
set d.oldy = GetUnitY(d.caster)
call SetUnitAbilityLevel(d.caster, EVADE_ID, 1) //Removes evasion if caster moved
else
call SetUnitAbilityLevel(d.caster, EVADE_ID, D.evasion) //Sets evasion if caster is near a tree and did not move
if HEAL_BASE > 0. then //Heals caster if he is near a tree and did not move
call SetUnitState(d.caster, UNIT_STATE_LIFE, UNIT_STATE_LIFE + d.heal)
endif
endif
else
if IsDestructableTree(d) then
call SetUnitAbilityLevel(d.caster, EVADE_ID, d.evasion) //Sets evasion if near a tree
if HEAL_BASE > 0. then //Heals if near a tree
call SetUnitState(d.caster, UNIT_STATE_LIFE, UNIT_STATE_LIFE + d.heal)
endif
endif
endif
else
call SetUnitAbilityLevel(d.caster, EVADE_ID, 1) //Removes evasion if not near a tree
endif
set d = null
endfunction
private function TreeCheck takes nothing returns nothing
local data d = GetTimerData(GetExpiredTimer())
set D = d
call EnumDestructablesInCircleBJ(AOE, l, function NearTrees) //Picks every destructable in range
set d.time = d.time + INTERVAL
if d.time >= d.duration then
call UnitRemoveAbility(d.caster, EVADE_ID) //Removes evasion at end of duration
call d.destroy()
endif
endfunction
private function Actions takes nothing returns nothing
local unit u = GetTriggerUnit()
local real x = GetUnitX(GetTriggerUnit())
local real y = GetUnitY(GetTriggerUnit())
local data d = data.create(u, x, y)
call UnitAddAbility(u, EVADE_ID) //Adds evasion.
call SetTimerData(d.t, d)
call TimerStart(d.t, INTERVAL, true, function TreeCheck)
set u = null
endfunction
//=============================================================
private function Cond takes nothing returns boolean
return GetSpellAbilityId()== SPELL_ID
endfunction
private function init takes nothing returns nothing
local trigger t = CreateTrigger()
local unit u
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT )
call TriggerAddCondition(t, Condition(function Cond))
call TriggerAddAction(t, function actions)
if EVADE_BASE > 0 then //Preload evasion ability
set u = CreateUnit(Player(15), 039;hfoo039;, 0., 0., 0.)
call UnitAddAbility(u, EVADE_ID)
call SetUnitAbilityLevel(u, EVADE_ID, EVADE_BASE+1)
call UnitRemoveAbility(u, EVADE_ID)
call RemoveUnit(u)
endif
set u = null
set t = null
endfunction
endscope
Thanks for any help.