A type does not allow...? Getting a syntax error with a struct

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"

:confused: :( :eek:

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 =  'A000'  //rawcode of the Forestborn spell
    private constant integer EVADE_ID =  'A001'  //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), 'hfoo', 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.
 

hgkjfhfdsj

Active Member
Reaction score
55
i think u meant D.newx = GetUnitX(D.caster)
and same with the rest in the same function

d is ur local destructable variable
D is ur global data struct (i dont think u declared it yet)
 

tommerbob

Minecraft. :D
Reaction score
110
I changed my local destructable variable to "dest", but I'm still getting the same syntax error.
 

hgkjfhfdsj

Active Member
Reaction score
55
only changed the destructable variable?
u dont have a referencable 'd' in that function. either change d to > D (u did set D = d in ur treecheck) then add D into global block (or if u want, into 'data' as a static field)
or add
local data d = D
to save u from changing the d to D in the whole function.
 

tommerbob

Minecraft. :D
Reaction score
110
Ahh, okay. So I added 'D' into a global block above the struct, and I still got the error, so then I moved it below the struct, and it worked fine. Is that correct? Why does it matter where I put the global block?
 

hgkjfhfdsj

Active Member
Reaction score
55
data struct is not declared when u put the global before the struct
similar to these scenarios

JASS:
local integer a = b*2 // undeclared b variable
local integer b

// ==== or ====

function a takes nothing returns nothing
    call b() //undeclared function b
endfunction

function b takes nothing returns nothing
endfunction
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top