| 12-27-2007, 10:58 AM | #1 |
I've been learning the usage of structs and scopes, and I'm a little confused on something. When declaring a "private global" within a scope, does this mean that it will not overwrite the data if the trigger is executed more than once? I cannot explain without an example. I do know that it allows you to use the same variable name in other scopes. JASS:scope somescope globals private group somegroup // Fear that this can be overwritten if executed twice.... endglobals struct somestruct timer t = CreateTimer() rect r = SomeRect //...some other contents... endstruct function end takes nothing returns nothing local timer t = GetExpiredTimer() local somestruct data = somestruct(GetHandleInt(t,"struct")) set unit = FirstOfGroup(somegroup) // An example of using the group after 20 seconds.. endfunction function start takes nothing returns nothing local somestruct data = somestruct.create() call GroupEnumUnitsInRect(somegroup , data.r, null) call SetHandleInt(data.t, "struct", data) call TimerStart(data.t, 20, true, function end) endfunction endscope If this trigger is called once, it will set units to group somegroup. Now, in 20 seconds somegroup is accessed at the timer end. If this trigger is called again, will it overwrite somegroup, or no because it is private? |
| 12-27-2007, 11:42 AM | #2 |
It's just like any global, so yes it would be overwritten. Private means that it just modifies where you can access the global from: JASS:scope SomeScope globals private group SomeGroup = CreateGroup() real X = 275.00 public real Y = 300.00 public real R = 55.00 endglobals function SomeFunc takes nothing returns nothing call GroupEnumUnitsInRange(SomeGroup, X, Y, R, BOOLEXPR_TRUE) //Ok because we are referencing SomeGroup inside the scope endfunction function SomeFunc2 takes nothing returns nothing local group SomeGroup = CreateGroup() //Bad because we're re-declaring SomeGroup call GroupEnumUnitsInRange(SomeGroup, X, Y, R, BOOLEXPR_TRUE) //Ok because we are referencing SomeGroup inside the scope endfunction endscope function SomeFunc3 takes nothing returns nothing call GroupEnumUnitsInRange(SomeGroup, X, Y, R, BOOLEXPR_TRUE) //Bad because we're trying to reference SomeGroup when we're not in that scope! endfunction function SomeFunc4 takes nothing returns nothing local group SomeGroup = CreateGroup() //Ok because we're not in the scope and there is no variable conflict call GroupEnumUnitsInRange(SomeGroup, X, Y, R, BOOLEXPR_TRUE) //Ok because SomeGroup exists as a local group in this function endfunction |
| 12-27-2007, 09:18 PM | #3 |
You use the private keyword if you want that only the functions inside the scope / library can access and / or modify the variable. Example: JASS:scope A globals private integer SpellID = 'A000' endglobals private function test takes nothing returns nothing call DisplayTimedTextFromPlayer(Player(0), 0,0,5, I2S(SpellID)) // it doesn't generate error because this function is part of the scope endfunction endscope function test takes nothing returns nothing call DisplayTimedTextFromPlayer(Player(0), 0,0,5, I2S(SpellID)) // it generates error. endfunction With this you can ensure that the variables, structs and functions in a scope can only be used inside the scope. To resume: private integer X : X only will be accessible inside the scope / library A public integer X : X can be called outside in the way A_X, and inside the scope in the normal way. |
| 12-28-2007, 04:25 AM | #4 |
I just came back to mapping after about a 7 month break. Where did this new "scope" come from. Is it built into the warcraft engine, or is it a 3rd party add-on. It looks like a "class" in visual basic. |
| 12-28-2007, 07:54 AM | #5 |
It is kind-of like a class. It's part of the new OOP-like syntax that Vexorian has created with the JASS NewGen Pack |
| 12-28-2007, 10:52 AM | #6 | ||
Quote:
I'm just getting used to this new concept as well but from what I've learned so far it makes your spells really fast, and is an almost alternative to handle vars. This is a mass shrink i did, just a mass bloodlust. It can shrink many units at a time without the least bit of lag, unlike when i used handle vars to do it. Im open to any criticism on this.
|
