| 11-27-2007, 02:29 AM | #1 | ||
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:
2. Quote:
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. 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 ************************************************************ 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 JASS:scope myscope globals private timer t = CreateTimer() private integer i = 0 endglobals ![]() |
| 11-27-2007, 02:43 AM | #2 |
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: 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 | ||||||
Quote:
Quote:
Quote:
Quote:
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:
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:
-- 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 |
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 |
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 |
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): 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 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: 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 |
