wc3campaigns
WC3C Homepage - www.wc3c.netUser Control Panel (Requires Log-In)Engage in discussions with other users and join contests in the WC3C forums!Read one of our many tutorials, ranging in difficulty from beginner to advanced!Show off your artistic talents in the WC3C Gallery!Download quality models, textures, spells (vJASS/JASS), systems, and scripts!Download maps that have passed through our rigorous approval process!

Go Back   Wc3C.net > Tutorials > JASS/AI scripts tutorials
User Name
Password
Register Rules Get Hosted! Chat Pastebin FAQ and Rules Members List Calendar



Reply
 
Thread Tools Search this Thread
Old 05-08-2007, 05:47 AM   #1
Toink
User
 
Join Date: Oct 2006
Posts: 1,086

Submissions (3)

Toink is on a distinguished road (17)

Send a message via Yahoo to Toink
Thumbs up Scopes

Scopes

This tutorial will explain how to use scopes. Previous JASS Knowledge is required. Requires vJass.

What is a scope?

A scope is similar to a library, but it does not get moved to the top of the map's script. Think of a library as a section of code, something like a folder which contains functions. Instead of having them in the custom script section, you can make libraries instead, put all of your desired functions there and organize it along with other libraries. If for instance your library requires some functions outside the library, you can use the line requires <library name>
By using that line, libraries that are required will be put "ontop" or before it in the map's header.

For example:
Collapse JASS:

library MyLibrary requires CSCache, CSSafety
....
....
endlibrary

library CSCache initializer InitCSCache //This is the function that starts up on map init
....
....
endlibrary

Since your library requires CSCache and CSSafety, the order of the libraries will be:

Collapse JASS:
CSCache
CSSafety
MyLibrary

A library however, is moved to the top of the map's script. In short, it's like it is moved to the custom script section, but in an order(remember the requires blah blah thing?)

Scopes, are not moved. They are still a section of code which can contain private globals, private functions and other public/private members. If you want to use the private members and private globals but don't want it to be moved to the top of the map's custom script, use scopes.

Explain it to me please.

How do you declare scopes you say? Simple. Just do this :
Collapse JASS:
scope YourScope'sName
endscope

What can be done inside a scope?

You can declare globals, private globals, functions, private functions and public functions. You can also declare structs and methods. Here's an example.

Collapse JASS:
scope WTF
    globals
        private unit u
        private integer lvl
     endglobals

    private function PrivateFunc takes nothing returns nothing
        call BJDebugMsg("Hi")
    endfunction

    public function PublicFunc takes nothing returns nothing
        call PrivateFunc()
        call BJDebugMsg("Hello")
    endfunction

endscope


What are private members and public members?

Privates are members of it's class. Privates can only be used inside the scope they are in. Privates can also have the same name as other functions/global vars without giving an error. For example :

Collapse JASS:
scope wtfart

    globals
        private unit u // This global can only be used inside the scope wtfart.
    endglobals
   
    function Func takes nothing returns nothing
         set u = GetTriggerUnit() // This function is inside the scope so it can freely use that private
         call KillUnit(u)
    endfunction

endscope

globals
    unit u // Notice that we are using the name u again.
endglobals

function OtherFunc takes nothing returns nothing
    set u = GetTriggerUnit()
    call KillUnit(u)
endfunction

Publics are the opposite of privates. They act just like privates except that they can be used by functions outside the scope. For example :

Collapse JASS:

scope wtfart
    
    private function PrivFunc takes nothing returns string
        return "Hi"
    endfunction

    public function PubFunc takes nothing returns nothing
        call BJDebugMsg(PrivFunc()) // Gets the value returned by the private
    endfunction

endscope

function Func takes nothing returns nothing
    call wtfart_PubFunc() //You have to use the name of the scope it is in as a prefix and add a _
    call PubFunc() // This will not work
    call ExecuteFunc("wtfart_PubFunc")// You still need the prefix
endfunction


Nested Scopes

A nested scope is a scope inside a parent scope, this scope is considered a child scope. Child scopes cannot declare members that were previously declared as private or global by a parent scope.

Child scopes are always public members, meaning you can access a child scope's public members from outside the parent scope. But you must add a prefix for the parend and the child scope. Below is an example :

Collapse JASS:
library ParentScope //Notice I used a library, you can nest a scope inside a library but you can't nest a library in a library/scope
    scope ChildScopeA
        globals
            private integer Rawr
        endglobals

        public function WTF takes nothing returns nothing
            call BJDebugMsg(I2S(Rawr))
        endfunction
    endscope

    scope ChildScopeB
        globals
            public integer I
        endglobals

        public function WTF takes nothing returns nothing
            call BJDebugMsg(I2S(I))
        endfunction
    endscope

As I've said, child scopes cannot declare public/private members that are already declared by the parent scope. For example :

Collapse JASS:

library LibraryA
    globals
        unit BibleDude
    endglobals

    scope ChildScope
        globals
            unit BibleDude // This will cause an error, you have redeclared the variable BibleDude
        endglobals
    endscope
endlibrary


There are also two constants you can use inside scopes. They are SCOPE_PREFIX and SCOPE_PRIVATE.

SCOPE_PREFIX returns the prefix of the scope concatenated with a '_' (underscore). It is the prefix you use to call public functions.

SCOPE_PRIVATE returns the name of the current prefix for private members.

Collapse JASS:
scope WTF

    private function Blarg takes nothing returns nothing
        call BJDebugMsg("...")
    endfunction

    function lala takes nothing returns nothing
         call ExecuteFunc(SCOPE_PRIVATE+"Blarg") //You need to call private functions with their prefixes, in this case the SCOPE_PRIVATE constant will return the prefix "WTF_"
    endfunction

endscope


Last edited by Toink : 08-20-2007 at 12:59 PM.
Toink is offline   Reply With Quote
Sponsored Links - Login to hide this ad!
Old 05-08-2007, 12:47 PM   #2
Whitehorn
SPOON!
 
Whitehorn's Avatar


Respected User
 
Join Date: Sep 1983
Posts: 4,899

Submissions (114)

Whitehorn is a name known to all (509)Whitehorn is a name known to all (509)Whitehorn is a name known to all (509)Whitehorn is a name known to all (509)Whitehorn is a name known to all (509)

Default

'It's like a Library' really doesn't explain what a Scope is. Anyone that knows what a scope is will find this useless. Those that don't will likely find it equally useless.
__________________
My Wargame

Be excellent to each other.
Whitehorn is offline   Reply With Quote
Old 05-08-2007, 12:55 PM   #3
Toink
User
 
Join Date: Oct 2006
Posts: 1,086

Submissions (3)

Toink is on a distinguished road (17)

Send a message via Yahoo to Toink
Default

Have you read everything else?
Toink is offline   Reply With Quote
Old 05-08-2007, 12:59 PM   #4
Whitehorn
SPOON!
 
Whitehorn's Avatar


Respected User
 
Join Date: Sep 1983
Posts: 4,899

Submissions (114)

Whitehorn is a name known to all (509)Whitehorn is a name known to all (509)Whitehorn is a name known to all (509)Whitehorn is a name known to all (509)Whitehorn is a name known to all (509)

Default

Quote:
Tune in for more as I add in more detailed explanations.

Waiting on it.

Quote:
<insert average non-sense here>

Is this really appropriate?
__________________
My Wargame

Be excellent to each other.

Last edited by Whitehorn : 05-08-2007 at 12:59 PM.
Whitehorn is offline   Reply With Quote
Old 07-01-2007, 11:46 PM   #5
PitzerMike
Alcopops
 
PitzerMike's Avatar


Tools & Tutorials Moderator
 
Join Date: Jan 2003
Posts: 2,791

Submissions (12)

PitzerMike is a splendid one to behold (643)PitzerMike is a splendid one to behold (643)PitzerMike is a splendid one to behold (643)PitzerMike is a splendid one to behold (643)

Approved Map: Pitzer's Minesweeper

Default

You should probably rewrite that sentece about what a scope is.
A scope in the context of vJass is much like a namespace, simply to avoid naming conflicts between systems.

I'm also awaiting the promised additions :)
__________________
Zoom (requires log in)
PitzerMike is offline   Reply With Quote
Old 07-02-2007, 12:03 AM   #6
Taur
#8 in posting (nolifeftw)
 
Join Date: Jul 2005
Posts: 4,027

Taur is a jewel in the rough (215)Taur is a jewel in the rough (215)Taur is a jewel in the rough (215)Taur is a jewel in the rough (215)

Default

and you should probably say that it requires VJASS
Taur is offline   Reply With Quote
Old 07-05-2007, 03:05 PM   #7
Mapz_Maker
User
 
Mapz_Maker's Avatar
 
Join Date: Nov 2006
Posts: 198

Submissions (1)

Mapz_Maker is on a distinguished road (12)

Default

and that this does NOT require previous Jass knowledge, this requires previoud vJass knowledge. Those are two totally different languages, and as of i can you Jass effectively and this tutorial breaks all the rules of jass, i realize this is not jass, this is vJass. I stopped Jassing about 1/29/07 so, i have not used vJass. And with one exception everything in vJass is for lazy jassers because I can do everything except globals endglobals somehow or another in Jass, and i get to organize the code the way i want to organize, rather than letting a program do that. (sorry vexorian and all others who use vJass but it is the truth, more unique solutions are devised when you don't have structs, unions and so on. This is not meant to be offensive this is expressing a perspective)
__________________
Trigger:
Rep Mapz_Maker
Events
WC3C - Mapz_Maker makes a post!
Conditions
Actions
Custom Script: loop
Custom Script: exitwhen 1 = 2
Custom Script: set Mapz_Maker's Rep = Mapz_Maker's Rep + 1
Custom Script: endloop
Mapz_Maker is offline   Reply With Quote
Old 07-05-2007, 03:49 PM   #8
Vexorian
Free Software Terrorist
 
Vexorian's Avatar


Technical Director
 
Join Date: Apr 2003
Posts: 14,905

Submissions (37)

Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)

Hero Contest #3 - 2nd Place

Default

There is nothing offensive about the NIH syndrome, it is actually understandable. Lame but understandable.

I am not sure though, how you are going to organize things correctly in Jass, manually? That's something that doesn't seem possible unless you like to add prefixes to code, but even there, private is something you can't get.

--
Edit: I must say, that of all vJASS features, scopes and libraries are the only ones I couldn't live without. The trigger editor is terrible at letting you organize code, and doing so manually is a symptom of masochism, and at the end you don't really organize anything at all.

Seriously, I could simply do things manually for everything else, including structs, I would take 120% more of the time typing that and my code would look ugly with all the array notation for an abstraction that is not an array, but it is possible to live without structs... Scopes on the other hand are crazy-useful . I don't think I would have finished the only map I ever made if it wasn't for them.

Not saying that everybody should use them, if you don't want to use other people's stuff, then make your own preprocessor for organizing code! It is VERY easy (definitely easier than doing the organization yourself) and it won't hurt your ego, + you will keep your sanity.
__________________
Zoom (requires log in)Wc3 map optimizer 5.0
Someone should fix .wav sound in this thing.
Zoom (requires log in)JassHelper 0.A.2.A
Turns your simple code into something that is complicated enough to work.
Faster != more useful
Vexorian is offline   Reply With Quote
Old 07-05-2007, 04:19 PM   #9
Mapz_Maker
User
 
Mapz_Maker's Avatar
 
Join Date: Nov 2006
Posts: 198

Submissions (1)

Mapz_Maker is on a distinguished road (12)

Default

lol, organize in the 'header' for the map, not the triggers. the triggers to be independent of each other but then have a 'library' at the top of the map. and btw, what is NIH stand for and how would you write a preprocessor? [and everything can be done in jass because it is! i have used an mpq editor to examine the work of vJass and it is... interesting.]

edit: and what does public/private matter when one can just go change a single word?

Summary!


organize in header.
triggers independent.
what does public/private matter when one can just go change a single word?
what does NIH stand for?
how do you write a preprocessor for WE?
this summary is pointless!

__________________
Trigger:
Rep Mapz_Maker
Events
WC3C - Mapz_Maker makes a post!
Conditions
Actions
Custom Script: loop
Custom Script: exitwhen 1 = 2
Custom Script: set Mapz_Maker's Rep = Mapz_Maker's Rep + 1
Custom Script: endloop

Last edited by Mapz_Maker : 07-05-2007 at 04:25 PM.
Mapz_Maker is offline   Reply With Quote
Old 07-06-2007, 12:32 AM   #10
Av3n
Roar!
 
Av3n's Avatar


Project Leader: TBR
Project Member: PoC
 
Join Date: May 2006
Posts: 1,853

Submissions (7)

Av3n is a jewel in the rough (240)Av3n is a jewel in the rough (240)Av3n is a jewel in the rough (240)Av3n is a jewel in the rough (240)Av3n is a jewel in the rough (240)

Hero #4 extra-official winner2008 Spell olympics - Fire - BronzeHero Contest #3 - 3rd Place

Default

Mapz maker. If you check the credits of JASSHelper document(HTML) You''ll see how he converted all of those keywords...

-Av3n
__________________

Thanks to FatherTime for the sig
.:
Current ProjectsSubmissions
Power of CorruptionMy Terrain
The Black RoadMy Resources
Strikeforce
Twitter
Av3n is offline   Reply With Quote
Old 07-10-2007, 12:02 PM   #11
Toink
User
 
Join Date: Oct 2006
Posts: 1,086

Submissions (3)

Toink is on a distinguished road (17)

Send a message via Yahoo to Toink
Default

Sorry for the long delay in the update. I completely forgot about this, :(

But anywho, I added info on nested scopes. Yay :p

@Mapzmaker:

And yes, it does need previous Jass knowledge. You can't code vJass if you don't know Jass, since vJass is exactly the same as Jass, except with some additions like structs and such.

vJass is quite better than Jass. In fact, it is also JASS, it's just translated to make it work and can ease your coding. If you don't like vJass, stick to good 'ol Jass, I wouldn't mind.

Last edited by Toink : 07-10-2007 at 12:06 PM.
Toink is offline   Reply With Quote
Old 08-19-2007, 08:29 AM   #13
PitzerMike
Alcopops
 
PitzerMike's Avatar


Tools & Tutorials Moderator
 
Join Date: Jan 2003
Posts: 2,791

Submissions (12)

PitzerMike is a splendid one to behold (643)PitzerMike is a splendid one to behold (643)PitzerMike is a splendid one to behold (643)PitzerMike is a splendid one to behold (643)

Approved Map: Pitzer's Minesweeper

Default

*approved*
__________________
Zoom (requires log in)
PitzerMike is offline   Reply With Quote
Old 08-22-2007, 09:50 PM   #14
emjlr3
Rehabbing
 
emjlr3's Avatar
 
Join Date: Jun 2005
Posts: 1,386

Submissions (14)

emjlr3 is a jewel in the rough (151)emjlr3 is a jewel in the rough (151)

Mapping Contest First Place

Send a message via AIM to emjlr3 Send a message via MSN to emjlr3
Default

can scope use initializers as libraries can?
__________________
emjlr3 is offline   Reply With Quote
Old 08-23-2007, 01:15 AM   #15
moyack
Evil Emoticon
 
moyack's Avatar


Respected User
Project Leader: PoC
 
Join Date: Jan 2006
Posts: 3,271

Submissions (17)

moyack is a splendid one to behold (661)moyack is a splendid one to behold (661)moyack is a splendid one to behold (661)moyack is a splendid one to behold (661)

AI Tournament #2 - 2nd PlaceHero Contest - Second place

Send a message via MSN to moyack
Default

Quote:
Originally Posted by emjlr3
can scope use initializers as libraries can?
I'm afraid its not possible.
moyack is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off


All times are GMT. The time now is 05:07 PM.


Donate

Affiliates
The Hubb http://bylur.com - Warcraft, StarCraft, Diablo and DotA Blog & Forums The JASS Vault Clan WEnW Campaign Creations Clan CBS GamesModding Flixreel Videos

Powered by vBulletin (Copyright ©2000 - 2014, Jelsoft Enterprises Ltd).
Hosted by www.OICcam.com
IT Support and Services provided by Executive IT Services