Public and Privates +rep

Reaction score
341
Well , ive seen many vJASS Systems and Spells using public and private functions. Ive also read some vJASS Tutorials and i dont really understand them. Could somebody please explain to me what they are and a good example use of them. + rep.
 

Trollvottel

never aging title
Reaction score
262
public can be refered to from outside the scope/library

privates are only for the scope/library

should not be so hard to find a use for this, huh
 
Reaction score
341
Haha , im a vJASS newb and trying to learn it, im am also confused about scopes

EDIT : ok , another question i think i understand structs , Basicly the main purpose it to replace locals , to make your code shorter?
 

Azlier

Old World Ghost
Reaction score
461
Okay, lets assume you have two healing functions.


JASS:

function Heal takes nothing returns nothing
//blah, blah, blah...
endfunction

//=================================
function Init takes nothing returns nothing
 local trigger t = CreateTrigger()
 call TriggerAddAction(t,Heal)
 call TriggerRegisterAnyUnitEventBJ(t,EVENT_HERE)
 set t = null
endfunction

//NEXT TRIGGER

function Heal takes nothing returns nothing
//Yap, yap yap...
endfunction

//==============================
function Init takes nothing returns nothing
 local trigger t = CreateTrigger()
 call TriggerAddAction(t,Heal)
 call TriggerRegisterAnyUnitEventBJ(t,EVENT_HERE)
 set t = null
endfunction


Now, when defining the second Heal function, there's going to be a syntax error. Since Heal is a good function name and plan to use it, what can you do besides adding some weird prefix? That's where scopes come in.

A scope is broken down into four words (or something like that).
scope - This declares the start of a scope.
HealAll - This is the name of the scope.
initializer - The tells the system that the Initializer function is next.
Init - This is the name of the chosen initializer. If you look below, you can actually see the Init function.

JASS:

scope HealAll initializer Init

private function Heal takes nothing returns nothing
//blah, blah, blah...
endfunction

//=================================
private function Init takes nothing returns nothing
 local trigger t = CreateTrigger()
 call TriggerAddAction(t,Heal)
 call TriggerRegisterAnyUnitEventBJ(t,EVENT_HERE)
 set t = null
endfunction

endscope

//NEXT TRIGGER
scope HealOne initializer Init

private function Heal takes nothing returns nothing
//blah, blah, blah...
endfunction

//=================================
private function Init takes nothing returns nothing
 local trigger t = CreateTrigger()
 call TriggerAddAction(t,Heal)
 call TriggerRegisterAnyUnitEventBJ(t,EVENT_HERE)
 set t = null
endfunction

endscope


Scopes add a prefix to private functions, so that you can use the same function name over and over, as long as they're private and in separate scopes. At least that's what I've learned...

Wow... I don't have warcraft III so I'm limited to JASS in notepad. It looks so much more professional with the coloring, even though I only know three events, how to display text, and explode units without a bj!

EDIT: Woah, TriggerHappy, weren't you the one who inspires me to learn JASS in the first place?
 
Reaction score
341
Haha , i was just messing around in world editor and learned this , and now i check back and you did the same thing. But what i dont get is , you cant call private functions from outside of the scope?....
 

Trollvottel

never aging title
Reaction score
262
But what i dont get is , you cant call private functions from outside of the scope?....

why do you think they are called "private"?^^
 

Azlier

Old World Ghost
Reaction score
461
If you want to be able to call them from outside the scope, it goes public function, not private. BEWARE: You can't have public functions with the same name AFAIK.
 

Azlier

Old World Ghost
Reaction score
461
A private function is easily called... if called within the scope in which it resides. To get them from somewhere else, you eed to use public.
 
Reaction score
341
oh.... It just needs to be inside the scope to be called. Thanks


UGH , i still have no idea on why you would need to use this
 

Darthfett

Aerospace/Cybersecurity Software Engineer
Reaction score
615
oh.... It just needs to be inside the scope to be called. Thanks


UGH , i still have no idea on why you would need to use this

It's to prevent you from having problems with functions with conflicting names, when creating/importing functions.

It's also nice so that you can name every trigger's InitTrig function

public/private function Init/InitTrig

public/private function Actions

public/private function Conditions

That way you don't have to change as much if you choose to copy/paste something.
 

saw792

Is known to say things. That is all.
Reaction score
280
You wouldn't...

All coding now is done in either a scope or a library. A library is like a scope, except it is automatically moved to the top of the jass script upon saving. Libraries are generally used for systems that are needed by multiple other functions.

I think somebody was confused about publics as well. You can certainly have a public function with the same name as another public function, as long as they are not in the same scope/library.
JASS:
function Test takes nothing returns nothing

compiles to

function Test takes nothing returns nothing


JASS:
public function Test takes nothing returns nothing

compiles to

function SCOPENAME_Test takes nothing returns nothing


JASS:
private function Test takes nothing returns nothing

compiles to

function SCOPENAME__Test+(Some random digits or something) takes nothing returns nothing
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top