[JASS] question about customizing functions

Status
Not open for further replies.
Level 13
Joined
Jun 23, 2009
Messages
299
That's BJDebugMsg's code, enjoy.
JASS:
function BJDebugMsg takes string msg returns nothing
    local integer i = 0
    loop
        call DisplayTimedTextToPlayer(Player(i),0,0,60,msg)
        set i = i + 1
        exitwhen i == bj_MAX_PLAYERS
    endloop
endfunction

BJ functions are not (ok, I admit that, it's obvious) natives, so you can replicate those functions changing the arguments in it if you know them. If you don't know them, download JNGP and use TESH in the Trigger Editor window.
 
Level 13
Joined
May 11, 2008
Messages
1,198
i wasn't asking for help in understanding how that function works...i'm trying to figure out how to make functions of my own here...so for example...
JASS:
function BJDebugMsg takes string msg returns nothing
    local integer i = 0
    loop
        call DisplayTimedTextToPlayer(Player(i),0,0,60,msg)
        set i = i + 1
        exitwhen i == bj_MAX_PLAYERS
    endloop
endfunction
you type this
call BJDebugMsg("This is a Message.")

JASS:
function BJDebugShortMsg takes string msg returns nothing
    local integer i = 0
    loop
        call DisplayTimedTextToPlayer(Player(i),0,0,5,msg)
        set i = i + 1
        exitwhen i == bj_MAX_PLAYERS
    endloop
endfunction

now i want to call this.
JASS:
call BJDebugShortMsg("This is a Message.")

where does the function go? is it just called function? do you not need to call it public or anything like that? put it in library or scope or struct or whatever?

i know i can simply copy that code and paste it over and over and over again...but i can only copy and paste one kind of thing at a time i'd rather be able to do something like
JASS:
call BJDebugShortMsg("This is a Message.")
than have to do this constantly:
JASS:
    local integer i = 0
    loop
        call DisplayTimedTextToPlayer(Player(i),0,0,5,"This is a Message.")
        set i = i + 1
        exitwhen i == bj_MAX_PLAYERS
    endloop
 
Level 6
Joined
May 7, 2009
Messages
228
You don't have to paste the function contents everywhere.
That's the entire point of functions. You can put the code in once, and then use it as many times as you want.

JASS:
function BJDebugShortMsg takes string msg returns nothing
    local integer i = 0
    loop
        call DisplayTimedTextToPlayer(Player(i),0,0,5,msg)
        set i = i + 1
        exitwhen i == bj_MAX_PLAYERS
    endloop
endfunction

This should work just fine. Paste it right under endglobals of whatever map you're using it in, and you can then just do
JASS:
call BJDebugShortMsg("Whatever")
like normal in your other code.
 
Level 13
Joined
May 11, 2008
Messages
1,198
actually i think i finally figured it out. basically...this is how you can be using a library.

i saw the TextTag system and it had public functions in the library.
these public functions are called from the other triggers to do the code.
i didn't check it with this sort of trigger specifically but it worked just fine with other functions that i wanted to do. it's a little tricky trying to figure out where the libraries are useful and where they aren't, i guess i'll be learning about that now. meh...now i have to figure out structs still lol. anyone know of a very simple struct trigger somewhere that i can be analyzing? i'm kindof one of those, learning by practical example guys so if there's someone else out there like me like that then perhaps you can post a link to a map with a trigger in it that helped you to learn how to use structs. i guess i've learned a bit about libraries now. i guess i'll supply the code and explain my new library.

it'll be for TDHT, i'll be posting the new version of it soon of course.

JASS:
//==============================================================================
//  TDHT - Library for The Demon Hunt Tournament by SanKakU -
//==============================================================================
//  THANKS TO : TEXT TAG - Floating text system by Cohadar - v4.0
//  I was able to learn how to make a library from examining that simple system
//==============================================================================
//  This particular system accomplishes a few things.
//  * allows slightly faster map initial loading time because less triggers are
//  registered.
//  * allows time to be saved while adding new triggers.
//  to use: call RUNNERPUE(nameoftrigger, thekindofevent) and that's it.
//  you can make your own teams from any combination of colors and edit the
//  functions like that.  like if you had a map with teams just like dota,
//  then you can make a function like SENTINELPUE and Player(1,2,3,4,5) and 
//  SCOURGEPUE Player(7,8,9,10,11) instead of RUNNERPUE and CHASERPUE and
//  instead of Player(2,3,4,5,6,7,8,9,11) and Player(0,1,10)
//  if you allow things like all pick then this won't work for spell triggers.
//  but it might still be useful for things like giving gold to enemy team of
//  a dying tower or hero or something like that.
//==============================================================================


library TDHT

globals    
endglobals

function FilterDebug takes nothing returns boolean
return true
endfunction

//
public function RUNNERPUE takes trigger trig, playerunitevent whichPlayerUnitEvent returns nothing
    call TriggerRegisterPlayerUnitEvent( trig, Player(2),whichPlayerUnitEvent, Filter(function FilterDebug) )
    call TriggerRegisterPlayerUnitEvent( trig, Player(3),whichPlayerUnitEvent, Filter(function FilterDebug) )
    call TriggerRegisterPlayerUnitEvent( trig, Player(4),whichPlayerUnitEvent, Filter(function FilterDebug) )
    call TriggerRegisterPlayerUnitEvent( trig, Player(5),whichPlayerUnitEvent, Filter(function FilterDebug) )
    call TriggerRegisterPlayerUnitEvent( trig, Player(6),whichPlayerUnitEvent, Filter(function FilterDebug) )
    call TriggerRegisterPlayerUnitEvent( trig, Player(7),whichPlayerUnitEvent, Filter(function FilterDebug) )
    call TriggerRegisterPlayerUnitEvent( trig, Player(8),whichPlayerUnitEvent, Filter(function FilterDebug) )
    call TriggerRegisterPlayerUnitEvent( trig, Player(9),whichPlayerUnitEvent, Filter(function FilterDebug) )
    call TriggerRegisterPlayerUnitEvent( trig, Player(11),whichPlayerUnitEvent, Filter(function FilterDebug) )
endfunction
//
public function CHASERPUE takes trigger trig, playerunitevent whichPlayerUnitEvent returns nothing
    call TriggerRegisterPlayerUnitEvent( trig, Player(0),whichPlayerUnitEvent, Filter(function FilterDebug) )
    call TriggerRegisterPlayerUnitEvent( trig, Player(1),whichPlayerUnitEvent, Filter(function FilterDebug) )
    call TriggerRegisterPlayerUnitEvent( trig, Player(10),whichPlayerUnitEvent, Filter(function FilterDebug) )
endfunction

endlibrary

anyway while TRYING to learn about structs and libraries and other stuff about jass i thought structs did like what i was trying to do, but it turned out to be libraries...heh. funny how things aren't what you expect. well, whatever, it's all so complicated...
as far as i recall, i used this for unit dying events and spell trigger events. there may be other events you could use it for too.

also, the PUE means player unit event so see it says whichPlayerUnitEvent that works with any of those kinds of events. if you needed others you might need to make a different function for them.
 
Status
Not open for further replies.
Top