luorax
Invasion in Duskwood
- Reaction score
- 67
Okay, so I have a problem with my snippet:
S O L V E D
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:
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: