[vJASS] Even more vJASS

Status
Not open for further replies.
operators are method calls built inside the program language

operators are : " = " " < " " > " " != " etc..

with operator keyword, you can make own operators like a method call

eg:

method operator i2 takes nothing returns integer
return i*i
endmethod

method operator i2= takes integer j returns nothing
set i = j/i
endmethod

in the egsample I made an operator i2 and a i2= . See how it ease the syntax

without operator:

set c = SquareRoot(i*i + i*i)
set i = j/i

with operators:

set c = SquareRoot(i2+i2)
set i2=j

its not a big difference here but can do realy comlex things with it

just think of it that the " i " represents something long and complicated

----------
method operator x2 takes nothing returns integer
return GetUnitX(struct.someunit)*GetUnitX(struct.someunit)
endmethod

method operator y2 takes nothing returns integer
return GetUnitY(struct.someunit)*GetUnitY(struct.someunit)
endmethod

without operator:

c = SquareRoot(GetUnitX(struct.someunit)*GetUnitX(struct.someunit)+GetUnitY(struct.someunit)*GetUnitY(struct.someunit))

with operator:

c = SquareRoot(x2+y2)

its only a basic thing you can use operators for. try out some thing
 
Status
Not open for further replies.
Back
Top