Syntax Error - struct

Rushhour

New Member
Reaction score
46
Hi, I get the Error:TowerUp.count is private at the marked line and I don't have a clue why, the function is inside the scope 0o!
JASS:

scope OrcTowers initializer InitTrig_System
struct TowerUp
    private unit array units [5]
    private real x
    private real y
    private integer count
    
    method createFinal takes nothing returns nothing
    local integer index=2
    loop
        exitwhen index >5 
        call RemoveUnit(.units[index])
        set index=index+1
    endloop
    endmethod
    
    method createDummy takes nothing returns nothing
        set .count=.count+1
        set .units[.count]=CreateUnit(GetOwningPlayer(.units[1]),'o00G',.x + 250. * Cos(((2-.count)*90.) * bj_DEGTORAD),.y + 250. * Sin(((2-.count)*90.) * bj_DEGTORAD),0.)
        call IssueTargetOrder(.units[.count],"move",.units[1])
        if .count==5 then
            call UnitRemoveAbility(.units[1],'A004')
            call UnitAddAbility(.units[1],'A00F')
        endif
    endmethod
        
    static method create takes unit u returns TowerUp
        local TowerUp tu =TowerUp.allocate()
            set tu.units[1] =u
            set tu.x=GetUnitX(u)
            set tu.y=GetUnitY(u)
            set tu.count=1
            call SetUnitUserData(u,tu)
        return tu
    endmethod
    
endstruct


private function UpgradeTower takes nothing returns nothing
local TowerUp tu
if TowerUp(GetUnitUserData(GetTriggerUnit())) ==0 then
    set tu=TowerUp.create(GetTriggerUnit())
else
    set tu=TowerUp(GetUnitUserData(GetTriggerUnit()))
endif

if  tu.count <5 then //here !
    call tu.createDummy()
else
    call tu.createFinal()
endif
endfunction

//here is only the initialization function
endscope
 
Reaction score
456
count is private to the struct, not to the scope. It has to be public if you want access to it.

Though you can make it [ljass]readonly[/ljass], which means user is only able to read it, but not write:
JASS:
if tu.count < 5 then //no error
    set tu.count = 5 //error
 

Rushhour

New Member
Reaction score
46
Ah thanks, I thought putting private before them would make them scope-private, not struct private.. !
Argh why didn't I think of this 0o.. thanks :D
Hm and how to access the public struct member?
tu.TowerUp_count or tu.TowerUp__count gives me syntax errors?!
 

Dinowc

don't expect anything, prepare for everything
Reaction score
223
instead of this:
JASS:
struct TowerUp
    private unit array units [5]
    private real x
    private real y
    private integer count

// ..............

endstruct

why don't you do this:
JASS:
private struct TowerUp
    unit array units [5]
    real x
    real y
    integer count

//................

endstruct


with this you can access struct's members from anywhere inside the scope
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top