Cannot convert unit to integer

luorax

Invasion in Duskwood
Reaction score
67
Okay, so I have a problem with my snippet:

S O L V E D

JASS:
library VertexColor uses AIDS
    
    // --- H A S H   B Y   J E S U S 4 L Y F ---
    //==========================================
    globals
        private constant integer HASH_NEXT = 53
        private constant integer MAX_HASH_VALUE = 8191
        private integer array HashedInt
    endglobals

    private function Hash takes integer i returns integer
        local integer hash = i - (i / MAX_HASH_VALUE) * MAX_HASH_VALUE
        
        loop
            exitwhen HashedInt[hash] == i
            if HashedInt[hash] == 0 then
                set HashedInt[hash] = i
                return hash
            endif
            set hash = hash + HASH_NEXT
            if hash >= MAX_HASH_VALUE then
                set hash = hash-MAX_HASH_VALUE
            endif
        endloop
        
        return hash
    endfunction
    
    // --- H E R E   B E G I N S   T H E   S Y S T E M ---
    //====================================================
    
    globals
        private boolean array UseCustomValues
        private integer array CustomRed
        private integer array CustomGreen
        private integer array CustomBlue
        private integer array CustomAlpha
    endglobals
    
    struct VertexColor extends array
        readonly integer Red
        readonly integer Green
        readonly integer Blue
        readonly integer Alpha
        
        readonly static boolean AllowAdd
        
        method operator red takes nothing returns integer
            return this.Red
        endmethod
        method operator green takes nothing returns integer
            return this.Green
        endmethod
        method operator blue takes nothing returns integer
            return this.Blue
        endmethod
        method operator alpha takes nothing returns integer
            return this.Alpha
        endmethod
        method modifyRed takes integer r returns integer
            if this.Red + r > 255 then
                set this.Red = 255
            elseif this.Red + r < 0 then
                set this.Red = 0
            else
                set this.Red = this.Red + r
            endif
            call SetUnitVertexColor(this.unit, this.Red, this.Green, this.Blue, this.Alpha)
            return this.Red
        endmethod
        method modifyGreen takes integer r returns integer
            if this.Green + r > 255 then
                set this.Green = 255
            elseif this.Green + r < 0 then
                set this.Green = 0
            else
                set this.Green = this.Green + r
            endif
            call SetUnitVertexColor(this.unit, this.Red, this.Green, this.Blue, this.Alpha)
            return this.Green
        endmethod
        method modifyBlue takes integer r returns integer
            if this.Blue + r > 255 then
                set this.Blue = 255
            elseif this.Blue + r < 0 then
                set this.Blue = 0
            else
                set this.Blue = this.Blue + r
            endif
            call SetUnitVertexColor(this.unit, this.Red, this.Green, this.Blue, this.Alpha)
            return this.Blue
        endmethod
        method modifyAlpha takes integer r returns integer
            if this.Alpha + r > 255 then
                set this.Alpha = 255
            elseif this.Alpha + r < 0 then
                set this.Alpha = 0
            else
                set this.Alpha = this.Alpha + r
            endif
            call SetUnitVertexColor(this.unit, this.Red, this.Green, this.Blue, this.Alpha)
            return this.Alpha
        endmethod
        method modify takes integer r, integer g, integer b, integer a returns nothing
            if this.Red + r > 255 then
                set this.Red = 255
            elseif this.Red + r < 0 then
                set this.Red = 0
            else
                set this.Red = this.Red + r
            endif
            if this.Green + g > 255 then
                set this.Green = 255
            elseif this.Green + g < 0 then
                set this.Green = 0
            else
                set this.Green = this.Green + g
            endif
            if this.Blue + b > 255 then
                set this.Blue = 255
            elseif this.Blue + b < 0 then
                set this.Blue = 0
            else
                set this.Blue = this.Blue + b
            endif
            if this.Alpha + a > 255 then
                set this.Alpha = 255
            elseif this.Alpha + a < 0 then
                set this.Alpha = 0
            else
                set this.Alpha = this.Alpha + a
            endif
            call SetUnitVertexColor(this.unit, this.Red, this.Green, this.Blue, this.Alpha)
        endmethod
        method setRed takes integer r returns integer
            if r > 255 then
                set this.Red = 255
            elseif r < 0 then
                set this.Red = 0
            else
                set this.Red = r
            endif
            call SetUnitVertexColor(this.unit, this.Red, this.Green, this.Blue, this.Alpha)
            return this.Red
        endmethod
        method setGreen takes integer r returns integer
            if r > 255 then
                set this.Green = 255
            elseif r < 0 then
                set this.Green = 0
            else
                set this.Green = r
            endif
            call SetUnitVertexColor(this.unit, this.Red, this.Green, this.Blue, this.Alpha)
            return this.Green
        endmethod
        method setBlue takes integer r returns integer
            if r > 255 then
                set this.Blue = 255
            elseif r < 0 then
                set this.Blue = 0
            else
                set this.Blue = r
            endif
            call SetUnitVertexColor(this.unit, this.Red, this.Green, this.Blue, this.Alpha)
            return this.Blue
        endmethod
        method setAlpha takes integer r returns integer
            if r > 255 then
                set this.Alpha = 255
            elseif r < 0 then
                set this.Alpha = 0
            else
                set this.Alpha = r
            endif
            call SetUnitVertexColor(this.unit, this.Red, this.Green, this.Blue, this.Alpha)
            return this.Alpha
        endmethod
        method setTo takes integer r, integer g, integer b, integer a returns nothing
            if r > 255 then
                set this.Red = 255
            elseif r < 0 then
                set this.Red = 0
            else
                set this.Red = r
            endif
            if g > 255 then
                set this.Green = 255
            elseif g < 0 then
                set this.Green = 0
            else
                set this.Green = g
            endif
            if b > 255 then
                set this.Blue = 255
            elseif b < 0 then
                set this.Blue = 0
            else
                set this.Blue = b
            endif
            if a > 255 then
                set this.Alpha = 255
            elseif a < 0 then
                set this.Alpha = 0
            else
                set this.Alpha = a
            endif
            call SetUnitVertexColor(this.unit, this.Red, this.Green, this.Blue, this.Alpha)
        endmethod
        method resetRed takes nothing returns integer
            local integer hash = Hash(this.unit)
            if UseCustomValues[hash] then
                set this.Red = CustomRed[hash]
            else
                set this.Red = 255
            endif
            call SetUnitVertexColor(this.unit, this.Red, this.Green, this.Blue, this.Alpha)
            return this.Red
        endmethod
        method resetGreen takes nothing returns integer
            local integer hash = Hash(this.unit)
            if UseCustomValues[hash] then
                set this.Green = CustomGreen[hash]
            else
                set this.Green = 255
            endif
            call SetUnitVertexColor(this.unit, this.Red, this.Green, this.Blue, this.Alpha)
            return this.Green
        endmethod
        method resetBlue takes nothing returns integer
            local integer hash = Hash(this.unit)
            if UseCustomValues[hash] then
                set this.Blue = CustomBlue[hash]
            else
                set this.Blue = 255
            endif
            call SetUnitVertexColor(this.unit, this.Red, this.Green, this.Blue, this.Alpha)
            return this.Blue
        endmethod
        method resetAlpha takes nothing returns integer
            local integer hash = Hash(this.unit)
            if UseCustomValues[hash] then
                set this.Alpha = CustomAlpha[hash]
            else
                set this.Alpha = 255
            endif
            call SetUnitVertexColor(this.unit, this.Red, this.Green, this.Blue, this.Alpha)
            return this.Alpha
        endmethod
        method reset takes nothing returns nothing
            local integer hash = Hash(this.unit)
            if UseCustomValues[hash] then
                set this.Red = CustomRed[hash]
                set this.Green = CustomGreen[hash]
                set this.Blue = CustomBlue[hash]
                set this.Alpha = CustomAlpha[hash]
            else
                set this.Red = 255
                set this.Green = 255
                set this.Blue = 255
                set this.Alpha = 255
            endif
            call SetUnitVertexColor(this.unit, this.Red, this.Green, this.Blue, this.Alpha)
        endmethod
        
        private method AIDS_onCreate takes nothing returns nothing
            local integer hash = Hash(this.unit)
            if UseCustomValues[hash] then
                set this.Red = CustomRed[hash]
                set this.Green = CustomGreen[hash]
                set this.Blue = CustomBlue[hash]
                set this.Alpha = CustomAlpha[hash]
            else
                set this.Red = 255
                set this.Green = 255
                set this.Blue = 255
                set this.Alpha = 255
            endif
        endmethod
        private static method AIDS_filter takes unit u returns boolean
            return true
        endmethod
        static method turnOffDefine takes nothing returns nothing
            set thistype.AllowAdd = false
            call PauseTimer(GetExpiredTimer())
            call DestroyTimer(GetExpiredTimer())
        endmethod
        private static method AIDS_onInit takes nothing returns nothing
            set thistype.AllowAdd = true
            call TimerStart(CreateTimer(), 1.5, false, function thistype.turnOffDefine)
        endmethod
        //! runtextmacro AIDS()
    endstruct
    
    function DefineBasicVertexColors takes integer id, integer r, integer g, integer b, integer a returns boolean
        local integer hash = 0
        debug if VertexColor.AllowAdd == false then
        debug     call BJDebugMsg("VertexColor: The define time is over!")
        debug     return false 
        debug endif
        set hash = Hash(id)
        set UseCustomValues[hash] = true
        if r < 0 then
            set CustomRed[hash] = 0
        elseif r > 255 then
            set CustomRed[hash] = 255
        else
            set CustomRed[hash] = r
        endif
        if g < 0 then
            set CustomGreen[hash] = 0
        elseif g > 255 then
            set CustomGreen[hash] = 255
        else
            set CustomGreen[hash] = g
        endif
        if b < 0 then
                set CustomBlue[hash] = 0
        elseif b > 255 then
            set CustomBlue[hash] = 255
        else
            set CustomBlue[hash] = b
        endif
        if a < 0 then
            set CustomAlpha[hash] = 0
        elseif a > 255 then
            set CustomAlpha[hash] = 255
        else
            set CustomAlpha[hash] = a
        endif
        return true
    endfunction
    
    function SetVertexColor takes unit whichUnit, integer red, integer green, integer blue, integer alpha returns nothing
        call VertexColor[whichUnit].setTo(red, green,blue,alpha)
    endfunction
    
    function ModifyVertexColor takes unit whichUnit, integer red, integer green, integer blue, integer alpha returns nothing
        call VertexColor[whichUnit].modify(red, green,blue,alpha)
    endfunction
    
    function ResetVertexColor takes unit whichUnit returns nothing
        call VertexColor[whichUnit].reset()
    endfunction
endlibrary

So this is the code. The JASSHelper highlights each row with the "SetunitVertexColor" function in the methods, and says what the title says. What's the problem? I'm oafish, it's true, but where's the problem?

EDIT: Note that it compiles perfectly without the methods with "SetUnitVertexColor" (like set, setRed, etc).

Thanks for the help in advance! :thup:
 

chobibo

Level 1 Crypt Lord
Reaction score
48
there's no unit struct member, you can't use this.unit, add a unit to the struct.
 

chobibo

Level 1 Crypt Lord
Reaction score
48
Oh, Sorry I don't know how to use AIDS, I thought that was a syntax error.

off-topic: there's something wrong with the jass tags, the script doesn't get highlighted in my browser, anyone having the same problem?
 

luorax

Invasion in Duskwood
Reaction score
67
Yes, I have the same problem.

@Weep: No problem. BTW it's the truth: I'm always doing the things too fast, and it leads to various errors and mistakes...
 

Bribe

vJass errors are legion
Reaction score
67
this.unit is converted to a function interface + trigger evaluation because of JassHelper's screwed up compilation, so it's likely to produce errors quite a bit. You just need to change every this.unit to GetIndexUnit(this).
 
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