HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Finally Decided to Read the Manual.

11-27-2007, 02:29 AM#1
Joker
I'll be updating this until i finish seeing as though I can't read all that in one day. I'll be posting questions about the stuff on the manual.

1.
Quote:
Originally Posted by Manual
Public members are closely related to private members in that they do mostly the same, the difference is that public members don't get their names randomized, and can be used outside the scope.
Aren't they complete opposites? I thought the Privates main job was to keep the function just in the scope/library. Also what does it mean by "...public members don't get their names randomized." ?

2.
Quote:
Originally Posted by Manual
Scopes can be nested, don't confuse this statement with `libraries can be nested´, in fact, you cannot even place a library inside an scope definition. You can however, have scope inside either library or scope definitions.
What is "nesting"?

3. So...from what I read, Scopes allow you do use Public/Private and child scopes do...?

4. SCOPE_PREFIX is for Publics while SCOPE_PRIVATE is for Privates right? How do these help? I thought ExecuteFunc was bad.

5. I have no idea how Keywords work. The example confuses me also.
Collapse JASS:
scope myScope

   private keyword B //we were able to declare B as private without having to actually
                     //include the statement of the function which would cause conflicts.

   private function A takes integer i returns nothing
       if(i!=0) then
           return B.evaluate(i-1)*2 //we can safely use B since it was already
                                    //declared as a private member of the scope
       endif
       return 0
   endfunction

   private function B takes integer i returns nothing
       if(i!=0) then
           return A(i-1)*3
       endif
       return 0
   endfunction

endscope
If they return nothing, what are the returns for? Also, since they are both Privates, where is the integer i going to come from?

************************************************************
How do scopes help and what can you use them for?

Here is a senario:
I want to make multiple spells with globals, but I want my globals to have the same name to keep them simple. Would this even be worth doing or was it not made for this purpose/kind of thing
Collapse JASS:
scope myscope
     globals
          private timer t = CreateTimer()
          private integer i = 0
     endglobals
I'm so lost.
11-27-2007, 02:43 AM#2
HINDYhat
I'll try my best to answer:
1.
private members (or functions) have the library/scope name added to them, plus a random integer when the script compiles. public members (or functions) have the library/scope name added to them when the script compiles, BUT they don't have the random integer. So in that case, public/private members/functions are very much nearly the same. If you want no change in the variable/function name, just don't add a public/private prefix :P

2.
Nesting is having one scope inside another. Here's a good example of nesting. See, the global name is the same, yet the script still compiles since each global is private to their scope:
Collapse JASS:
scope A
    globals
        private integer N
    endglobals
    scope B
        globals
            private integer N
        endglobals
    endscope
endscope

3.
Yes?

4.
As far as I know, ExecuteFunc still r0x.

5.
Heh, I haven't looked into keywords yet :P

************************************************************
If you want your globals to have the same name, yes you could do that.

Here, cohadar explains alot about vJass. This might help in your learning of scopes and the such:
http://www.wc3campaigns.net/showthread.php?t=97708
11-27-2007, 02:57 AM#3
Vexorian
Quote:
If they return nothing, what are the returns for? Also, since they are both Privates, where is the integer i going to come from?
It is a mistake, they are supposed to return integer, the second question is silly, it is an example, it doesn't have to be ultra realistic, just an example, integer i is coming from another function that I didn't type, how about that?


Quote:
How do scopes help and what can you use them for?
My life philosophy is that if you can't think of a good use for something you shouldn't care about understanding it.

Quote:
I want to make multiple spells with globals, but I want my globals to have the same name to keep them simple. Would this even be worth doing or was it not made for this purpose/kind of thing
Well, you are close in that guess I should say.

Quote:
4. SCOPE_PREFIX is for Publics while SCOPE_PRIVATE is for Privates right? How do these help? I thought ExecuteFunc was bad.
ExecuteFunc is "bad", but there are still legacy systems using them, so if you want to keep using scopes and still use, let's say caster system's OnAbilityEvent you would need those.

If you are creating something new, .execute() is just much cooler than ExecuteFunc, as in : ("It is faster, doesn't cause issues with "optimizers" and you can't make the map crash from missusing it (you just get syntax errors in that case )

Quote:
Aren't they complete opposites? I thought the Privates main job was to keep the function just in the scope/library. Also what does it mean by "...public members don't get their names randomized." ?
In the case of scopes , public is not the opposite of private, the opposite of private would be not using neither private or public. public just adds a prefix to your variables and functions.

Randomized, for private to work correctly I add random prefixes to private members, it is quite a lame idea, but that's the way it works.

3. Child scopes are just plain useless, if you ask. But it is like you can split one scope into two different portions or something like that...

Quote:
What is "nesting"?
It's a manual, not a tutorial so it expects you to know some stuff or two. For example nesting is like ... when you have an if statement inside another one, it is a "nested if" .

--
Most practical case for scopes:
Have you ever made a map, and tried to implement various Jass systems on it? I noticed many people made their spells and systems and declared their own H2I function, what happens next is that if someguy tries to paste both systems into his maps there will be a syntax error for function redeclaration, this is a general issue with Jass in the regard that all functions are in the global scope, which means that in normal Jass, once a function reserves a name you cannot use that name again.

When you are coding stuff that human beings are supposed to use, you want to avoid name conflicts, and an easy way of doing so would be not to reserve names you don't need to reserve... by using an scope and adding private to H2I's declaration, your system will safely use that function, but outside that scope such name is not going to be "reserved" so, something else might use it as well.

keyword is just a workaround, in order to use a private/public member you need to declare it first, else there are issues, with keyword you can prevent those issues, 1 times out of 100 you will not have to care about keyword, but it is a good lifesaver .
11-27-2007, 04:02 AM#4
Joker
Alright. I think I'm starting to understand all these crazy vJass things. Libraries put the codes inside to the top of the script, scopes act like libraries, but does not move the codes to the top. Scopes aid in creating systems(?), structs are some sort of an array that you can use like a variable, methods increase struct capabilities(?), extending structs allow structs to be used in the other struct it is delared in(?), dynamic arrays are really big structs(?), and function interface uses functions sort of like variables(?).

I hope most of that's right...
11-27-2007, 04:11 AM#5
Dil999
Libraries put codes at the top of the script and let you use public/private.
Scopes act as libraries but DONT put the codes at the top of the script/
Scopes basically let you have private/public functions/
Structs are, the bast way I can explain them, sets or clusters of variables, and you can create and destroy specific sets ofthem.
Methods are functions inside structs.
Extending libraries basically puts one library above the other (ex library A extends B, B is put above A)
No idea what dynamic arrays area
No idea what interfaces are.
11-27-2007, 07:33 AM#6
Pyrogasm
If you really need to read any more about Scopes....

At any rate, interfaces are designed to save you time and to create pseudo-inheritence in which you can have things extending other things so you don't have to make new types of those things to get the code to compile. A physics-engine-related-example is the best (though this is really more of the structs-extending-structs aspect):
Collapse JASS:
struct Object
    unit U
    real BounceFactor

    method Move takes nothing returns nothing
        //Whatever
    endmethod
    method SetMass takes real newMass returns nothing
        //Whatever
    endmethod
    method SetBounce takes real newBounce returns nothing
        set this.BounceFactor = newBounce
    endmethod
    method Jump takes real JumpForce returns nothing
        call JumpObject(this.U, JumpForce) //Pointless, but whatever
    endmethod
endstruct

struct Paladin extends Object
     //This struct also has the other methods "Object" has
     //(Move, SetMass, SetBounce, Jump)

     //But you can also overwrite to have its own Jump method
     method Jump takes real JumpForce returns nothing
         call JumpObject(this.U, Jumpforce-1.50) //Just for difference
     endmethod
endstruct

struct BouncyBall extends Object
     method SetBounce takes newBounce returns nothing
         set this.BounceFactor = newBounce*2.75 //It inherits variables too
     endmethod
endstruct
An everyday use for interfaces would be when you want to call a function with two or more different types of structs as an argument but don't want to make two functions:
Collapse JASS:
interface Both
    integer X = 5
endinterface

struct A extends Both
    integer I = 1
endstruct

struct B extends Both
    integer I = 2
endstruct

function GetNumber takes Both SomeStruct returns nothing
    call BJDebugMsg("I*X = "+I2S(SomeStruct.I*SomeStruct.X))
endfunction

Function interfaces, on the other hand, are entirely separate things. A function interface is essentially a code array because you can't have code arrays. So you'd use them like this:
Collapse JASS:
function interface SomeCode
    function SomeOtherFunction takes nothing returns nothing
endinterface

struct SomeStruct
    SomeCode CallbackCode
    timer T = CreateTimer()

    method StartCallback takes nothing returns nothing
        call TimerStart(T, 1.00, false, this.CallbackCode)
    endmethod
endstruct
endstruct