• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!

Function call

Status
Not open for further replies.
This is all vJass...

JASS:
function interface TwoReals takes real a, real b returns nothing

This creates a function interface, which is basically like defining a new type of variable. Functions can be saved to it. Now, you can just do something like:

JASS:
function interface TwoReals takes real a, real b returns nothing //define the function interface (or type)

globals
    TwoReals MyFunc //define the global function variable
endglobals

function Multiply takes real a, real b returns nothing
    call BJDebugMsg(R2S(a*b))
endfunction

function Add takes real a, real b returns nothing
    call BJDebugMsg(R2S(a+b))
endfunction

function Test takes nothing returns nothing
    set MyFunc = Multiply //save the Multiply function to the variable
    call MyFunc.execute(1.5, 2.5) //run the function with parameters

    set MyFunc = Add //save the Add function to the variable
    call MyFunc.execute(1.5, 2.5) //run the new function with parameters
endfunction

This will output:

3.750
4.000


The only limitation is that the functions you save in the variable must all have the same parameters and return type. Note that if you want to store the returned value of the function in a variable you can do local <type> r = MyFunc.evaluate(<params>)
 
Level 2
Joined
Jul 17, 2009
Messages
27
Huh?

You're confusing an intended feature (hashtables), with an unintended bug (unsafe typecasting).

Blizzard would not implement hashtables only to take them away in the next patch. That would be stupid.

Blizzard never intended for the return bug to happen, nor be so critical for mapmakers. The gamecache was never designed to be used the way most maps use it.
 
Status
Not open for further replies.
Top