• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Overloading funcs with vJass, possible?

Status
Not open for further replies.
Level 5
Joined
Nov 27, 2007
Messages
85
Is it possible to overload functions in jass?
This would be extremely useful for large maps, like mine...

Simple example:
JASS:
// display text to all players
    function echo takes string s returns nothing
        call DisplayTextToForce(GetPlayersAll(), s)
    endfunction

// function with the same name, but uses only one player
    function echo takes player p, string s returns nothing
        call DisplayTextToPlayer(p,0,0,s)
    endfunction

If this isn't possible in vJass, can it be implemented with other tools, like cJass?
 
Level 14
Joined
Nov 23, 2008
Messages
187
cJass allows define overloading. Example:
JASS:
define {
  msg(text)          = DisplayTextToForce (GetPlayersAll(), text)
  msg(text, p)       = DisplayTextToPlayer(Player(p), 0.0, 0.0, text)
  msg(text, p, x, y) = DisplayTextToPlayer(Player(p), x, y, text)
}

void test() {
  msg("test 1")
  msg("test 2", 1)
  msg("test 3", 2, 0.1, 0.1)
}

// ===>>>

function test takes nothing returns nothing
  call DisplayTextToForce (GetPlayersAll(), "test 1")
  call DisplayTextToPlayer(Player(1), 0.0, 0.0, "test 2")
  call DisplayTextToPlayer(Player(2), 0.1, 0.1, "test 3")
endfunction
But overloaded defines should take different number of arguments to be processed correctly.
 
Status
Not open for further replies.
Top