• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[vJASS] Globals and Scopes inside

Status
Not open for further replies.
Level 16
Joined
Mar 3, 2006
Messages
1,564
Let me get what I understand straight ... (correct me if I am wrong)

Libraries: will move whats inside it to the top of the map script; whats inside it includes: functions, structs, globals (what else ? )

Scopes: will keep whats inside as it is (i.e. will not move whats inside to the top)

Questions:

1) If scope will keep things as it is why do I add it in the first place ?

2) How a scope inside library will work, will it move whats inside the library to the top and keep whats inside the scope as it is ?

3) How globals inside scopes will function properly; isn't globals supposed to be in the top of the script, the scope keyword will make the global not to move to the top, isn't it ?
 
Level 13
Joined
Sep 13, 2010
Messages
550
libraries and scopes are similar except libraries are moved to the top. Globals are independent from these things. They will be ALLWAYS at the top, then libraries, then Global declaration like units, sounds, destructables... Jass functions like structs, scopes. Scopes CAN require libraries and other scopes but libraries CAN ONLY use other libraries. Cause required library will be higher on the priority list, placed upper than the other. But the fact that scopes aren't moved to the top, they can't be declared before libraries. There is no way to put library inside an other library, this way you can't put scope in a library, or a library into a scope.

Libraries also let privatization and they let initialization functions as far as I know

Sorry if it is ununderstandable.
 
Level 13
Joined
Sep 13, 2010
Messages
550
What I understand from your post is:
Scopes can require library but not be nested inside it


<EDIT>
Another question:

You mentioned Globals then global declaration. whats the difference ?

Yes, thats it

with Globals I mentioned global variable declaration and global *value* declaration used in GUI, you know unit variable's, sound variable's, dialog variable's, also integer array variable's values
 
Level 16
Joined
Mar 3, 2006
Messages
1,564
with Globals I mentioned global variable declaration and global *value* declaration used in GUI, you know unit variable's, sound variable's, dialog variable's, also integer array variable's values

Ahh ... I remembered something. I took a look at a map script, if I remember correctly in the top was globals and was <TYPE> <NAME> and when skipped down the file a bit I found those variables were set to values like Footman_<0001> or something like that.
 
Level 16
Joined
Mar 3, 2006
Messages
1,564
Something like that (its from the helper manual)
JASS:
scope cool
    public struct a
        integer x
    endstruct

    globals
        a x
        public a b
    endglobals


    public function test takes nothing returns nothing
        set b = a.create()
        set b.x = 3
        call b.destroy()
    endfunction

endscope

function test takes nothing returns nothing
 local cool_a x=cool_a.create()
    set a.x=6
    call a.destroy()
endfunction
what will be its location in the map script ?
 
Level 13
Joined
Sep 13, 2010
Messages
550
It will be in the mess of other triggers and jass functions( after the global things ). After the scope there will be that function "test". Some struct function will be placed in the header( as libraries ). Globals:
JASS:
    globals
        a x
        public a b
    endglobals
// and from struct
    integer (array) x
They will be at the top. I am using only libraries so I don't have any problems ^^
 
That scope will be moved to the end of the map script, but since all the code is public, it will end up at the top.

Scopes shouldn't be used in public resources most of the time.
They allow you to make implicit requirements. (Meaning no one will know what's required and they're obliged to read the documentation.)

Scopes are awesome for map-making though.
Still, I don't use them.
I use structs:

JASS:
struct System extends array

    // declare globals here

    // methods here

    private static method onInit takes nothing returns nothing
        // init code here
    endmethod
endstruct

edit
@geries, actually it's:

JASS:
globals
    integer x
    integer cool_b
    constant integer s__a__type = 1
endglobals
//From struct
integer array x

:p
 
Level 29
Joined
Mar 10, 2009
Messages
5,016
Libraries is a must do (imo) if you're creating a system, but I usually use Scopes
for simple things like spells and initialization/setup...

globals if NOT private nor public can be used anywhere in the map, only
functions cant do what global does (except structs)...

if you want in the middle, you could edit your code in the Map Header, which is
at the center of order of placement...

orders of placement;
1) Libraries
2) Map Header
3) Scope
 
Status
Not open for further replies.
Top