• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

why scope/lib

Status
Not open for further replies.
Level 37
Joined
Mar 6, 2006
Messages
9,243
Spells should be scopes mostly.

Libraries are compiled before scopes. Usually spells require external functions like knockback, damage detection or unit indexer. So you would call some functions from other resources from the spell's code. Now if the systems are libraries and your spell is a library, it is not guaranteed that your spell is compiled first, and the function calls will fail as the called functions aren't compiled yet. If your spell is a scope, then the libraries are coded before that.
 
Level 37
Joined
Mar 6, 2006
Messages
9,243
so I need scopes if I use libs for my spell to make it work.

Not necessarily as you can use library abc requires def where abc and def are both libraries.

Seems ok and if I remember right you didn't need to use methods inside scopes?

You don't need to...structs use methods, and I code all my spells using structs and methods.
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
I like your "pointfull" comments Almia

but on the other hand, the other comment was good.
Scopes and libraries allows you to use keyword private for globals or scopes within libraries or functions, making it easier to code because you dont need to remember which name you used where.

With prefix private, you can have global unit variable of name trigunit in all spells and it will not collide

Libraries are mostly used as systems or pieces of code that must be callable from anywhere from the code. You cant say where exactly will Scope with your spell be placed, but you can exactly say that library will be right below globals(and struct constructors/deconstructors/onDestroys[muhaha]) so you know you can call functions from libraries from anywhere

another good thing about libraries, as maker pointed out, is the advantage of keyword uses/requires
This makes, so that if you have Library A and Library B requires Library A, the library A will always be above Library B.
(There is also keyword optional, which means you dont really need the library)

Last but not least good feature of libraries/scopes is initializer
if you use keyword initializer, you can make custom functions that will run when map is loading without using the horrible InitTrig keyword

for instance:
JASS:
scope AA initializer init
    private function init takes nothing returns nothing
    endfunction
endscope

you can also have scope in scope
JASS:
scope A
    scope B
    endscope
endscope

JASS:
library AAD initializer init requires AAA, AAB, optional AAC
    private function init takes nothing returns nothing
    endfunction
endlibrary


library AAC initializer init requires AAB, AAA
    private function init takes nothing returns nothing
    endfunction
endlibrary

library AAB
endlibrary

library AAA 
endlibrary

//or also:

library AAQ
    private scope sco
    endscope
endlibrary

/*
    be aware, that Vexorians JH has a glitch in which it will not compile private scopes
    like this, you have to use dummy unes like:
*/

library AAQ
    scope AAQA
    endscope
    private scope sco
    endscope
endlibrary
 
Status
Not open for further replies.
Top