about functions (private/public)

Dois

New Member
Reaction score
1
lets say I name my function "Filter_Function" in some random trigger...

Can I name another function in another trigger the same?

And what does the private/public prefix do? As in "private function" or "public function"

Are functions "global" or do they only work for that trigger they are in? What is public/private for?

Edit: and now that ive just found out in JASS Craft that theres "filterfunc" what is that?

edit: ok thx uberplayer
 

Dois

New Member
Reaction score
1
oh so those library and scope and public and private are all newgen stuff?

I can not use them and W.E. will still have the same efficacy right?

And uh... whats vJASS? normal JASS? or another NewGen mod pack thing?
 

soulreaping

New Member
Reaction score
17
Private or public declarations can be used only in scopes and libraries.

Here is an example:
JASS:
scope SomeScope

private function Hello takes nothing returns nothing
         call BJDebugMsg("Hello")
endfunction

public function World takes nothing returns nothing //-> You can access this function from anywhere in the script using SomeScope_World
         call BJDebugMsg("World")
endfunction

endscope


Basically, the JASSHelper compiler actually compiles private functions as SomeScope___Hello and public functions as SomeScope_World.

If you don't give a membership for a function (private/public), the function will have no prefix and you can't declare a function with the same name and without membership either.

This is the same for variables and structs.

I suggest reading through the vJass manual, it's in the NewGen folder under jasshelper directory.


EDIT:
vJass is an extension for JASS which adds libraries, scopes, structs and a lot of new features.
 

Dois

New Member
Reaction score
1
ok i think im going too deep...

i dont have newgen and all that so... yeah... i didnt know public / private and all that were part of it...

thanks for the help...

Edit: so anyway... are "function"s global? or are they only part of the trigger you put them in. As in can I Have make functions with the same name in different triggers??

Edit: well i have a billion questions so... heres more

can i do
JASS:
    call AddSpecialEffectLocBJ( L, "Abilities\\Spells\\Orc\\WarStomp\\WarStompCaster.mdl" )
    call DestroyEffect( bj_LastCreatedEffect )


instead of "call DestroyEffectBJ( GetLastCreatedEffectBJ )"

because the "call DestroyEffectBJ( GetLastCreatedEffectBJ )" seems like its just making one big round. (according to what I see at the bottom area of JassCraft)
 

phyrex1an

Staff Member and irregular helper
Reaction score
447
Edit: so anyway... are "function"s global? or are they only part of the trigger you put them in. As in can I Have make functions with the same name in different triggers??
Functions are global.


can i do
JASS:
    call AddSpecialEffectLocBJ( L, "Abilities\\Spells\\Orc\\WarStomp\\WarStompCaster.mdl" )
    call DestroyEffect( bj_LastCreatedEffect )


instead of "call DestroyEffectBJ( GetLastCreatedEffectBJ )"

because the "call DestroyEffectBJ( GetLastCreatedEffectBJ )" seems like its just making one big round. (according to what I see at the bottom area of JassCraft)
Yes you can. But it isn't the most optimized way.
The preferred way is:
JASS:
call DestroyEffect(AddSpecialEffectLoc("Abilities\\Spells\\Orc\\WarStomp\\WarStompCaster.mdl",  L))

Notice the absence of BJ and the different argument order. We use the native AddSpecialEffectLoc instead of the blizzard.j AddSpecialEffectLocBJ.
A lot (not all) of the blizzard.j functions are just wrappers around natives and are therefore a completely waste to use.
 

GoGo-Boy

You can change this now in User CP
Reaction score
40
And Dois you forget one thing. When you create your triggers without scopes or libraries you have to set every functionname you put in that trigger with the prefix "Trig_Triggername_", else you get syntax error. This way you basically can't create global functions inside a trigger ( at least, as said, not without scopes and libraries). You surely can put them to the maphead though.
E.g.:
You call your trigger Kill_Unit. You want to make a for group action which you want to name GroupActions. Now the name of the function would be:
function Trig_Kill_Unit_GroupActions .........
 

Dois

New Member
Reaction score
1
ok thanks phyrex1an... at least im understanding it right...

and GoGo-Boy - I don't like the (Trig_) prefix infront of everything so I remove them and theres no problem... Is there something im understanding wrong from what you're saying?

As an example
JASS:
function Permanent_Immolation_Conditions takes nothing returns boolean
    return GetLearnedSkillBJ() == 'A000'
endfunction

function Permanent_Immolation_Actions takes nothing returns nothing
    call SetPlayerAbilityAvailableBJ( false, 'A000', GetOwningPlayer(GetTriggerUnit()) )
    call SetPlayerAbilityAvailableBJ( true, 'A000', GetOwningPlayer(GetTriggerUnit()) )
endfunction

//===========================================================================
function InitTrig_Permanent_Immolation takes nothing returns nothing
    set gg_trg_Permanent_Immolation = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Permanent_Immolation, EVENT_PLAYER_HERO_SKILL )
    call TriggerAddCondition( gg_trg_Permanent_Immolation, Condition( function Permanent_Immolation_Conditions ) )
    call TriggerAddAction( gg_trg_Permanent_Immolation, function Permanent_Immolation_Actions )
endfunction


That triggers works with no problems/errors...

am i missing something?
 

GoGo-Boy

You can change this now in User CP
Reaction score
40
It works without? I thought I have experienced that it doesn't :/
hmmm for sure... it gave me syntax error because I used TriggerAddCondition where I still had Trig_....
Oh crap... thank you then ^_^ now I can leave it away, it always bugged me :d
Seems like I've read a tutorial or sth where it was like that and then used it for my first trigger attempts until it became standard to me.
 

soulreaping

New Member
Reaction score
17
I suggest after you master the basics of JASS you should download NewGen and use vJass as it has much more features for intermediate JASSers to use so you can do much more things that with regular JASS would be either difficult or very slow.
 

GoGo-Boy

You can change this now in User CP
Reaction score
40
Guess why he's asking all this questions concerning vJASS? He works through JassCraft.
 
General chit-chat
Help Users

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top