Global Functions?

jomik

New Member
Reaction score
17
Hey, how can I make a function, that I can use in ALL my other triggers? :O
Thanks in advance.
 

Xorifelse

I'd love to elaborate about discussions...........
Reaction score
87
JASS:
library globalfunctions
    public function myGlobalFunction takes nothing returns nothing

    endfunction
endlibrary 

library foo requires globalfunctions
    // Scope of globalfunctions is accessible.
endlibrary

scope bar
    // Scope of globalfunctions is accessible.
endscope
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
Use public or don't add any prefixes.

JASS:
library lol 
    public function Hehe takes nothing returns nothing
    endfunction

    function Hoho takes nothing returns nothing
    endfunction
endlibrary

function Haha takes nothing returns nothing
    call lol_Hehe() //Add <scope_name>_function for public
    call Hoho() //No need to add anything.
endfunction
 

jomik

New Member
Reaction score
17
@King, but if I dun add any prefix, how do I know if the function is loaded before the function that uses it? Cuz it has to be in the right order?
And where do you put the library thingy? :O
 

Flare

Stops copies me!
Reaction score
662
@King, but if I dun add any prefix, how do I know if the function is loaded before the function that uses it? Cuz it has to be in the right order?
And where do you put the library thingy? :O

The library declaration will place all code contained within the library at the top of the map's compiled script. That way, it's accessible to all code located below it.

If the code using the generic function library is located within a separate library, you will have to do as Themis showed and add a requirement to the library declaration (i.e. [ljass]library MyLib requires GenFuncLibrary[/ljass])

As regards placement of the library, it doesn't really matter. You can just create a new trigger, convert it to custom text, delete the generated code and start off with
JASS:
library GenericFunctions
//don&#039;t forget to add some functions here <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite7" alt=":p" title="Stick Out Tongue    :p" loading="lazy" data-shortname=":p" />
endlibrary

and JASSHelper will do the rest.


The public prefix that kingking was talking about will just alter the name of the function when called from outside it's declared library - taking kingking's example...
JASS:
library lol 
    public function Hehe takes nothing returns nothing
    endfunction

    function Hoho takes nothing returns nothing
      call Hehe () //since I&#039;m calling the public function hehe from WITHIN the library it was declared in, the library name prefix does not have to be added
    endfunction
endlibrary

function Haha takes nothing returns nothing
    call lol_Hehe() //Add &lt;scope_name&gt;_function for public
    call Hoho() //No need to add anything.
endfunction



Bear in mind that library declaration requires NewGen World Editor. If you don't have it (although it's really worth getting), you can simply add your 'global' functions to the Map Header (if you take a look at the list of triggers at the left side of the Trigger Editor, they are branching down from a map icon, with your map's name beside it - click that to view the Map Header)
 

jomik

New Member
Reaction score
17
... Dude I did read that guide, I was just unsure how to make sure it got loaded first, as he didn't say anything about Libraries in romek's guide...

Now that's 2 not usefull posts you've made today ? :O
 

Nestharus

o-o
Reaction score
84
Actually it did say it very directly in the vJASS guide and in very clear details.

Would you like me to quote it?


Furthermore, the vJASS guide comes with vJASS and is also on the wc3c site.

Also I don't appreciate -rep for giving you a pointer, this is the last time I'm ever helping you.


I stand by my comment.


from vJASS
Libraries

Yet another issue with World editor and Jass was that it is impossible to control the order of triggers in the map's script when saved. The custom script partially solved the problem but it is really problematic to ask users to paste things there, it is also anti-modular programming to keep it full of unrelated stuff.

The library preprocessor allows you to keep your top functions in the top and being able to control where each one goes. It also has an smart requirement support so it will sort the function packs for you.

The syntax is simple, you use library LIBRARYNAME or library LIBRARYNAME requires ONEREQUIREMENT or library LIBRARYNAME requires REQ1, REQ2 ...

Remember to mark the end of a library using the endlibrary keyword .

library B
function Bfun takes nothing returns nothing
endfunction
endlibrary

library A
function Afun takes nothing returns nothing
endfunction
endlibrary

If JassHelper finds this command, it will make sure to move the Afun and Bfun functions to the top of the map's script, so the rest of the map's script can freely call Afun() or Bfun().

Notice that it would be uncertain to know what would happen if Afun() was called from a function inside the B library. The command is to move libraries to the top, but we wouldn't know if B went before or after A.

If a function inside library B needed to call a function inside library A we should let JassHelper know that A must be added before B. That's the reason the 'requires' keyword exists:

library B requires A

function Bfun takes nothing returns nothing
call Afun()
endfunction

endlibrary

library A

function Afun takes nothing returns nothing
endfunction

endlibrary

Note: For senseless reasons: requires, needs and uses all work correctly and have the same function in the library syntax.

It will move Afun to the top of the map and it will place Bfun after it, Bfun can now freely call Afun()

A library can have multiple requirements, just separate them by commas:

library C needs A, B, D
function Cfun takes nothing returns nothing
call Afun()
call Bfun()
call Dfun()
endfunction
endlibrary

library D
function Dfun takes nothing returns nothing
endfunction
endlibrary

library B uses A
function Bfun takes nothing returns nothing
call Afun()
endfunction
endlibrary

library A
function Afun takes nothing returns nothing
endfunction
endlibrary

The result in the top of the map would be:

function Afun takes nothing returns nothing
endfunction
function Dfun takes nothing returns nothing
endfunction
function Bfun takes nothing returns nothing
call Afun()
endfunction
function Cfun takes nothing returns nothing
call Afun()
call Bfun()
call Dfun()
endfunction

or maybe:

function Dfun takes nothing returns nothing
endfunction
function Afun takes nothing returns nothing
endfunction
function Bfun takes nothing returns nothing
call Afun()
endfunction
function Cfun takes nothing returns nothing
call Afun()
call Bfun()
call Dfun()
endfunction

or :

function Afun takes nothing returns nothing
endfunction
function Bfun takes nothing returns nothing
call Afun()
endfunction
function Dfun takes nothing returns nothing
endfunction
function Cfun takes nothing returns nothing
call Afun()
call Bfun()
call Dfun()
endfunction

It would depend on the order WE saves the scripts in the input file, but notice that since the requirements were set accordingly to the usage of functions by each library none of the 3 possible ways would cause any compile error.

Make sure to remember that:

* Library names are Case Sensitive.
* If library A requires library B and library B requires library A , there's a cycle and JassHelper will popup a syntax error.
* If library A requires a library that requires B and library B requires A, the cycle is still there.
* You can't nest libraries.
* Libraries might have globals blocks, as of version 0.9.B.0 library requirements determine the order in which these variables are added, notice that this warranty does not exist in prior versions.

It is also difficult to control what code is executed first, that's the reason libraries also have an initializer keyword, you can add initializer FUNCTION_NAME after the name of a library and it will make it be executed with priority using ExecuteFunc , ExecuteFunc is forced so it uses another thread, most libraries require heavy operations on init so we better prevent the init thread from crashing. After the initializer keyword the 'needs' statement might be used as well.

The initializers are added to the script in the same order libraries are added. So if library A needs B and both have initializers then B's inititalizer will be called before A's.

Notice the initializer is a function that takes nothing .

library A initializer InitA requires B


function InitA takes nothing returns nothing
call StoreInteger(B_gamecache , "a_rect" , Rect(-100.0 , 100.0 , -100.0 , 100 ) )
endfunction

endlibrary

library B initializer InitB
globals
gamecache B_gamecache
endglobals

function InitB takes nothing returns nothing
set B_gamecache=InitGameCache("B")
endfunction

endlibrary

B's initializer will be called on init before A's initializer.

Hints:

* The library_once keyword works exactly like library but you can declare the same library name twice, it would just ignore the second declaration and avoid to add its contents instead of showing a syntax error, it is useful in combination with textmacros.
* Older versions of vJass had a different syntax for libraries, that started with //! this was eventually deprecated and will now pop a syntax error out.

Hints: As of 0.9.Z.0, the declaration of a library will create a true boolean constant called LIBRARY_libraryname. Requirements may also be optional (prefix an optional keyword before the requirement name) which means that the library will be moved bellow that requirement, but if the requirement is not found, no syntax error will appear. These may be useful with another new 0.9.Z.0 feature: static ifs.
 

jomik

New Member
Reaction score
17
Ahh dude sorry, you see I were talking about Romek's vJASS guide as I said :O I'll give you your rep back. I were just in a pretty pissed mood :O
I don't think that is from his tutorial :O Can you link me?

EDIT: And you should probably explain yourself better instead of posting stuff that can be misunderstood like that, and is basically of no use :O - You should atleast have linked the tutorial when you wrote about it...
 

Nestharus

o-o
Reaction score
84
Here is from a quick search I did on The Helper with libraries..

http://www.thehelper.net/forums/showthread.php?t=135305&highlight=library+requires


If you want to know where the vJASS guide is, you can google vJASS Manual and first link will tell you where, which is a post from this forum.


If you want to read the online guide you can go to www.google.com and search for jass helper manual and I promise it'll be the very first thing that comes up.

You can also google vJASS Guide and you'll get a guide I haven't quite finished that also includes a library chapter and all necessary details as the first link




These are the points I'm making.



And if you want to make it easier... there's a link on the very top of this forum called What is JASS and how to learn it. It links to vJASS manual, JASS Manual, etc...
 

jomik

New Member
Reaction score
17
And if I didn't know that I had to use a library :O I wouldn't search for it :p
You know, generally it's pretty bad to post something like:
If you had read any guide... even the vJASS guide you would have already known this.

/sigh

It doesn't help at all, and there's usually a reason for people asking...
 

Nestharus

o-o
Reaction score
84
If you are using vJASS then you can look in the official vJASS guide for something that could do what you need since vJASS does include extra things.


If you are using plain JASS then you could look into alternatives like vJASS and cJASS first : ).



My point is first understand the language you are using, then ask the questions. If you don't learn the language then you can't ask the questions because you don't know all the tools open to you.



These guides were written to prevent questions asking about tools open to you, so it is your job to read them first : P.


The day Zinc came out do you want to know the very first thing I did? I read the Zinc Manual.

Whenever there is a new cJASS, I read the cJASS Manual. If I'm looking to do something with code or w/e and I'm a little fuzzy on some portions of a manual, I go to the manual and open all chapters that may be relevant to what I'm thinking of.


As a result of this practice and another practice, I rarely ever need help =).


It'd be very helpful if other people did the same thing because it'd stop questions like "how do I order code" or "how do I put code at top of the map" or "raw coding" and etc from being asked.


So I still stand by that post -.-.



In epic scale languages with lots of tools open to them like regex, I google my question...
 

jomik

New Member
Reaction score
17
Well, the reason I'm asking is because I'm trying to learn the language, and it just seemed easier to ask here than to start on some search hunt, when I didn't know the words to search for :O
Also alot of people here would easily be able to point me there, like you were? :O
 

Nestharus

o-o
Reaction score
84
So what if 100 people came in and asked the same question that a guide answered and that other people already asked?


Or what if simple questions were constantly asked that were already clearly depicted in a guide.


It takes time for someone to read over your post and answer it etc. You need to take other people into consideration when you ask a question. Is your question really worth someone taking time and effort to answer, or can it be answered through a search?


Questions should only be asked when you don't have the ability to solve it yourself.


Being too lazy to find an answer is not a good thing.
 

jomik

New Member
Reaction score
17
Yeah, but I did try and search, dude, what the fuck is there to freak out about ? Are you really that slow a reader? Or are your time really that valueable?! OMG...
 

Nestharus

o-o
Reaction score
84
If you had searched then we wouldn't be here right now. I already made that much clear =)

Also wasn't freaking out at all : D. Again, I was just trying to give you a pointer ;p
 

Romek

Super Moderator
Reaction score
964
If you don't have anything constructive to say, then don't say anything.
If all you're gonna do is have a big-headed attitude, and think that your work is the best, then shut up.

Asking questions such as these is fine. Some guides are simply too lengthy, dull, or don't explain things well.
My tutorial simply doesn't cover libraries; they'll be covered in the sequel.
 

Nestharus

o-o
Reaction score
84
My comments weren't about my work nor were they about me thinking this is best or that is best.

It was about trying to get people to be able to help themselves rather than always relying on others, similar to what good teachers do.

I won't back down and I still stand by my first post fully. People should be able to answer most of their own questions. They should only ask a question when they don't have the ability to figure it out. They have 0 growth when they just go and ask someone and they get nothing out of it. Also, it makes people spend time and effort on something that they could be better spending on something else.

Also, it's a common practice to search for your question first or to look in related guides before going and asking it. I see it as a tip on every forum I visit in something like "how to get help." Are you telling me that every forum is wrong and that people love to spend their time answering the same question in many different threads or that they love linking to these guides? I always get the impression that they don't enjoy this. I know I don't. I like asking challenging questions that aren't covered in guides or that haven't been asked a million times. Easy questions are easy because you don't even have to know the answer to answer them -.-. A lot of the time I just do a google search and provide the link from the first result I get... that is utterly pointless and a complete waste of time on everyone's part, and if you tell me that me doing a google search for someone else and giving them the link isn't a waste of time then I think you are absolutely mad.

giving me -rep won't change that. Banning me won't change that either.
 

jomik

New Member
Reaction score
17
Dude, I did search before I posted this thread... I'm not that stupid... I just wanted it clarified. I see what you mean, and it's true, but I don't see why this thread is that bad? :O
 

Nestharus

o-o
Reaction score
84
Dude, I did search before I posted this thread... I'm not that stupid... I just wanted it clarified. I see what you mean, and it's true, but I don't see why this thread is that bad? :O


Well, then I do apologize. You can understand my concern though when I can directly link many sources from official guides and other related posts through quick Google searches though, and when I can take out a whole chapter from the vJASS Official Guide by Vexorian that goes over this very issue : ).


Romek, if you do want to continue this though I do suggest we do so privately : ), unless of course you want to make a public spectacle of it.


Also, I never directly or indirectly say that you are at all stupid. I did mention laziness, but that wasn't directed at you ; ).
 
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