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.
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top