Libraries, how they work?

Phubar

Ultra Cool Member
Reaction score
30
Hi all,
like the name of the topic i want to know how trigger libraries work in general lines.
Can you link a simple tutorial or explain in a very easy way what can i do with them?
I just want to know what are them made for, not a step by step explanation on how to use them. That maybe later :)
 

Slapshot136

Divide et impera
Reaction score
471
for programming in general, libraries are a set of functions (with a good comments) that let you then import them for use in your own code - for example a common library would be a math library, which allows you to use things like power of, square of, change of base, etc. - yes, you can code all of that yourself, but libraries usually already exist for such stuff and have good documentation + examples, such that there isn't much benefit for you to write them yourself
 

Siretu

Starcraft 2 Editor Moderator
Reaction score
293
As slapshot said, libraries contains code. It's a way to easily distribute the code.

Imagine that you wrote a physics engine in the SC2 editor. It works nice and is easy to adapt to other players' maps. You could just have this code in a map and link the map to people and then they can open it and copy the triggers over to their own map.

However, to make this easier, there are .SC2Library files. When you export a library you've made, people can import it directly into their map without having to open both maps and copy in between.
 

Darthfett

Aerospace/Cybersecurity Software Engineer
Reaction score
615
EDIT: I didn't realize this was within the SC2 zone and not the WC3 zone, please disregard this post (keeping it because the information may be useful to someone).

vJass libraries allow you to:

  • Name an initializer function whatever you want
  • Require other libraries (name re-ordering of the functions; standard JASS requires all functions must be defined before their use, excluding recursive calls)
  • Avoid name conflicts (functions are renamed)
  • Declare functions public/private for encapsulation
The most common use of having a library is to modularize and encapsulate a bit of code, which is very useful when distributing code, as you can simply copy and paste it in a map. It is also useful for separating concerns, which helps code readability and maintenance.

Scopes are very similar to libraries. They provide all the same capabilities except:
  • Cannot be required by other libraries (scopes are always placed after other libraries)
  • Cannot require other libraries (scopes automatically 'require' libraries because they are always placed after. They cannot reliably use other scopes.
IIRC you can nest libraries within libraries, scopes within libraries, and scopes within scopes, but not libraries within scopes.
 

Phubar

Ultra Cool Member
Reaction score
30
Tnx for all the explanations!
Unfortunately for you i'm a very big noob so i have to ask some more questions...
The first is :
When you talk about "code" do you mean "triggers" too?
Others will come after an answer :)
 

Phubar

Ultra Cool Member
Reaction score
30
Ok, but in order to make a useful library i have to make only general triggers?
I mean if a put a trigger like
Code:
Condition
"Batman" enters region "Villain's cove"
Action
Create a "Villain security guard" in center of "Villain's cove" region
it wont work becouse in this trigger i use variables that cannot be used in every map.
Or worse, if i dont use variables but i use directly the name of the region (Region1) or the unit (Marine 123.45,34.50) the trigger will return error. Or not?
 

Slapshot136

Divide et impera
Reaction score
471
Ok, but in order to make a useful library i have to make only general triggers?

yes - you can use variables, and make functions that require certain variables as input (such as a hero, a region, and an enemy), but they should be generalized if you intend to make a library for them

any triggers that involve objects specific to your map (region1, marine1, etc.) should just be regular map triggers

I wouldn't worry too much about making libraries if you are just starting out..
 

Phubar

Ultra Cool Member
Reaction score
30
I'm not new to the editor, i can handle quite well the trigger module and now i'm looking to expand my knowledge to other aspects of the editor :)
Now i have to help some friend making a custom campaign and all the maps have to have the same triggers for load and save the upgrades bought in the game and in the main menu (like the original sc2), so can i insert those triggers in a lib and insert this lib in the mod file of the custom campaign?​
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      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