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!
anyway, if one is private, it should not give you errors... but the fact that your scope does not have an initializer function would cause an error (sometimes bypassed by JH, but makes the code not being able to run in-game)
private globals are useful if your code has several functions, since locals are only usable on the function where they are created... and because locals are created everytime, and needs to be nulled, so using private globals results to less function calls...
and also private globals are useful for constant things...
JASS:
globals
private constant integer TRY = 0
endglobals
/*
The global is created only once as opposed to using the local which is created every time the function is called
*/
function example takes nothing returns nothing
local integer try = 0
endfunction
so you mean there will be only one global declaration? (e.g)1st Trigg declares blah blah global and 2nd Trigg declares another blooh blooh global <-- that cant be?
A code block is a structure used in programming. It defines how to treat what's inside of it. For example, a globals block contains global variables inside of it, meaning anything put into a globals block is treated as a global variable. You cant put a function into a global block can you? : ).
A scope block defines scope for a set of blocks, which is wherever a thing exists. For example, the scope of a local variable is the function it is defined inside of while that function is running** (its scope begins when it is declared and ends when the function ends).
Blocks always start with the blockname and end with endblockname, just like globals endglobals.
Scope blocks are primarily used to allow things to have access modifiers on them. If something is in the global scope, it can't have an access modifier because it's not contained inside of anything, If something is in a scope, it is contained in that scope and can get an access modifier.
private/public are access modifiers, which can be applied to fields, globals, functions, and scopes (although a private scope can't be at the top of any scope, have to have a public first).
It runs in that order, and then in that structure you have module initializer -> struct initializer -> library/scope initializers.
So first it runs all module initializers in that order (from first library to last thingie), then all struct initializers, then regular initializers (library/scope). This is why people use module initializers for general resources now : ).
Scopes aren't really anything complicated, they just act like containers for code.
Imagine you have a pile of junk.
Anyone can take that and do whatever they want. The junk represents normal code, just sitting around.
Once we add a scope, it is kind of like adding a box.
What does that do? Yeah... nothing. Anyone can still just open the box and take whatever they want. However, boxes (scopes) in this case allow us to put sticky glue on whatever we want to keep in there. That represents private.
So when you do something like this:
JASS:
globals
integer fun = 0
endglobals
globals
integer fun = 6
endglobals
It will give an error. If you wrap them in a scope:
JASS:
scope A
globals
integer fun = 0
endglobals
endscope
scope B
globals
integer fun = 6
endglobals
endscope
It will still give an error. However, if you add "private" to any of them (or both), it will make that global unique, so you can use the same name in another scope:
JASS:
scope A
globals
private integer fun = 0
endglobals
endscope
scope B
globals
private integer fun = 6
endglobals
endscope
No error. That means our junk won't be messed with outside of the scope.
As far as other features go... public is something you can mostly ignore. It is kind of like having no prefix, but it can prevent naming collisions. (In the case above, you could add public as the prefix instead, and it would still work fine, but that means that the junk can be messed with outside of the scope, if you want it to be)
initializer is just to point to a function to call on map initialization. (kind of like the GUI event) It is usually just for setup.
You should take what you wrote and take some of the stuff from the scope chapter (to cover everything about scopes) and submit some of the tuts from the huge manual thingie ;D.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.