ShadowInTheD
Active Member
- Reaction score
- 12
Is there a way to set functions equal to variables, or calling them specifically to an object?
function modify takes unit u, location loc returns nothing
call SetUnitPositionLoc(u, loc)
endfunction
function act takes nothing returns nothing
unit cast = GetTriggerUnit()
location tarl = GetSpellTargetLoc()
call modify(cast,tarl)
endfunction
funtion change takes integer itemid returns nothing
if GetItemTypeId(itemid) == 039;Item039; then
//do actions
endif
endfunction
call change(GetEnumItem())
You could have a function take the item id and do actions based on that.
If functions are objects then we may as well have interfaces for them.
The syntax for function interfaces is:JASS:function interface name takes (arguments) returns (return value)
It is actually similar to a function declaration.
Variables/values of a function interface type may be called using execute() and evaluate() as defined above:
To assign to variables of a function interface type you first need to get a function's pointer. The syntax to get them is understandable if you assume that every declared function interface will get as static members the functions found in the map script that follow its argument/return value rules.
JASS:function interface Arealfunction takes real x returns real function double takes real x returns real return x*2.0 endfunction function triple takes real x returns real return x*2.0 endfunction function Test1 takes real x, Arealfunction F returns real return F.evaluate(F.evaluate(x)*F.evaluate(x)) endfunction function Test2 takes nothing returns nothing local Arealfunction fun = Arealfunction.double //syntax to get pointer to function call BJDebugMsg( R2S( Test1(1.2, fun) )) call BJDebugMsg( R2S( Test1(1.2, Arealfunction.triple ) )) //also possible... endfunction
Could you explain this to me? Will it allow me to set like the variable "a[1] = someFunction"? or something similar?
function interface associativeFunc takes integer itemType returns nothing
function ItemDoStuff takes integer itemType returns nothing
call BJDebugMsg("Hi!")
endfunction
struct Wrapper
integer itemType
associativeFunc whichFunc
endstruct
function TryItOut takes nothing returns nothing
local Wrapper w = Wrapper.create()
set itemType = 039;Whoa039;
set whichFunc = associativeFunc.ItemDoStuff
//Now we want to run some function with some item.
call w.whichFunc.execute(w.itemType)
endfunction