Why use scopes?

Magentix

if (OP.statement == false) postCount++;
Reaction score
107
I looked into some people's spells and noticed they used scopes.

The obvious advantage would be the ability to use the same function names, but save for that, why would I use scopes?

Does it destroy some globals or something else that would increase performance?
 
> Does it destroy some globals or something else that would increase performance?

No, it makes everything more organized and allows you to use privates (functions, globals, structs, other scopes inside it, etc.)

Imagine you want to use the function H2I. This is a very popular function (or at least was) putting it in scope would save the mapper needless function deleting.
 
>>This is a very popular function (or at least was) putting it in scope would save the mapper needless function deleting.
Putting it in a scope are just useless...lol
You forgot to "private" it.
 
>Putting it in a scope are just useless...lol.. You forgot to "private" it.
What do you mean? I think he did not: "..organized and allows you to use privates.."
 
First of all one of the main goals of vJass is to make systems, things made by other people, easy to implement. Another is organization.
A (not so good) example would be that you make a could of spells that aren't MUI and use some globals for them. For example it would make sense to use globals such as caster (unit), target (unit or XY) etc.
Now obviously you can't have two variables with the same name. You could name these two "a" and "b" in spell one and "c" and "d" in spell two, but that would turn into a nightmare when it comes to modifying. You can also use something long like "global_MySpell1_caster", but thanks to scopes you can just make it private and call it caster as much as you like.
Furthermore why use
function MySpell1_actions takes nothing returns nothing
or
function MySpell1_timercallback takes nothing returns nothing
when you can simply have
public function Actions takes nothing returns nothing
and
public function TimerCallback takes nothing returns nothing
in all of your spells. Much easier to read, isn't it?

It's also awesome for common functions like H2I as already stated. What if someone wants to implement two systems with handle vars? Sure, someone who is adept at Jass can remove the function doubles, but a beginner might be confused on which functions to get rid of...
 
As a precompiler, vJass doesn't add any "real" functionality - all the features are there to make it easier for the map-maker to design and implement efficient code.

Like SFilip said, scopes make it easy to organize your code and also to add other peoples systems where the names of globals and functions may otherwise conflict.
 
Thanks all, I got it now...


> public function Actions takes nothing returns nothing

I thought only privates "stayed within" the scope?
 
"private" means that the function's name (and all calls to it within the scope) will be randomized.
"public" means that the function gets an underscore followed by the scope's name as a sufix (public Actions inside myscope becomes Actions_myscope).
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • The Helper The Helper:
    It is weird seeing a way more realistic users online number
  • The Helper The Helper:
    Happy Tuesday Night!
    +1
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    News portal has been retired. Main page of site goes to Headline News forum now
  • The Helper The Helper:
    I am working on getting access to the old news portal under a different URL for those that would rather use that for news before we get a different news view.
  • Ghan Ghan:
    Easily done
    +1
  • The Helper The Helper:
    https://www.thehelper.net/pages/news/ is a link to the old news portal - i will integrate it into the interface somewhere when i figure it out
  • Ghan Ghan:
    Need to try something
  • Ghan Ghan:
    Hopefully this won't cause problems.
  • Ghan Ghan:
    Hmm
  • Ghan Ghan:
    I have converted the Headline News forum to an Article type forum. It will now show the top 20 threads with more detail of each thread.
  • Ghan Ghan:
    See how we like that.
  • The Helper The Helper:
    I do not see a way to go past the 1st page of posts on the forum though
  • The Helper The Helper:
    It is OK though for the main page to open up on the forum in the view it was before. As long as the portal has its own URL so it can be viewed that way I do want to try it as a regular forum view for a while
  • Ghan Ghan:
    Yeah I'm not sure what the deal is with the pagination.
  • Ghan Ghan:
    It SHOULD be there so I think it might just be an artifact of having an older style.
  • Ghan Ghan:
    I switched it to a "Standard" article forum. This will show the thread list like normal, but the threads themselves will have the first post set up above the rest of the "comments"
  • The Helper The Helper:
    I don't really get that article forum but I think it is because I have never really seen it used on a multi post thread
  • Ghan Ghan:
    RpNation makes more use of it right now as an example: https://www.rpnation.com/news/
  • The Helper The Helper:

      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