• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!

[JASS] No out-scopes-globals in scopes?

Status
Not open for further replies.
Level 21
Joined
Dec 9, 2007
Messages
3,096
Hey there.

I am still working on my n00b fire bolt spell, and I have another difficulty.

Well, I mixed all the scopes and their functions in one trigger to make importing easier and I still have one damned global variable and I want to get rid of it.

I have two scopes, FireBoltsCreation and FireBoltsMovement.
I use a global in the FireBoltsMovement wich is initialized inside the scope, and it works. but I need one global in both scopes, FireBolts.
If I try to initialize it outside the scopes, it doesn't work.
Should I initialize it in both scopes? (One time in each?)

For those who want to know the code...
JASS:
//~~~ Starting Scopes
//~~~~~~ Star of Creation

scope FireBoltsCreation initializer Init
private function Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == 'A001' ) ) then
        return false
    endif
    return true
endfunction

private function Actions takes nothing returns nothing
    local location p1 = GetUnitLoc(GetSpellAbilityUnit())
    local location p2 = GetSpellTargetLoc()
    local location pp = PolarProjectionBJ(p1, 15.00, AngleBetweenPoints(p1, p2))
    call CreateUnitAtLocSaveLast( GetOwningPlayer(GetSpellAbilityUnit()), 'u000', pp, AngleBetweenPoints(p1, p2) )
    call GroupAddUnit( udg_FireBolts, bj_lastCreatedUnit )
    call SetWidgetLife( bj_lastCreatedUnit, 3.00 )
    call SetUnitUserData( bj_lastCreatedUnit, ( GetHeroInt(GetSpellAbilityUnit(), true) * GetUnitAbilityLevel(GetSpellAbilityUnit(), 'A001') ) )
    call RemoveLocation(p1)
    call RemoveLocation(p2)
    call RemoveLocation(pp)
endfunction

//===========================================================================
private constant function AntiLeak takes nothing returns boolean
    return true
endfunction

private function Init takes nothing returns nothing
    local trigger t = CreateTrigger()
    local filterfunc f = Filter(function AntiLeak)
    local integer i = 0
    loop
        call TriggerRegisterPlayerUnitEvent(t, Player(i), EVENT_PLAYER_UNIT_SPELL_EFFECT, f)
        set i = i + 1
        exitwhen i >= 16
    endloop
    call TriggerAddCondition(t, Condition( function Conditions ) )
    call TriggerAddAction(t, function Actions )
    call DestroyFilter(f)
    set f = null
endfunction
endscope

//~~~~~~ End of creation
//~~~Switching Scopes
//~~~~~~ Start of Movement

scope FireBoltsMovement initializer Init

globals
    private group Targets
endglobals

function Trig_Fireball_Movement_Func001Func003002003001 takes nothing returns boolean
    return ( GetUnitState(GetFilterUnit(), UNIT_STATE_LIFE) > 0 )
endfunction

function Trig_Fireball_Movement_Func001Func003002003002 takes nothing returns boolean
    return ( IsUnitEnemy(GetFilterUnit(), GetOwningPlayer(GetEnumUnit())) == true )
endfunction

function Trig_Fireball_Movement_Func001Func003002003 takes nothing returns boolean
    return Trig_Fireball_Movement_Func001Func003002003001() and Trig_Fireball_Movement_Func001Func003002003002()
endfunction

function Trig_Fireball_Movement_Func001Func004Func001C takes nothing returns boolean
    if ( ( CountUnitsInGroup(Targets) >= 1 ) ) then
        return true
    endif
    if ( ( GetUnitState(GetEnumUnit(), UNIT_STATE_LIFE) <= 0.00 ) ) then
        return true
    endif
    return false
endfunction

function Trig_Fireball_Movement_Func001Func004C takes nothing returns boolean
    if ( not Trig_Fireball_Movement_Func001Func004Func001C() ) then
        return false
    endif
    return true
endfunction

function Trig_Fireball_Movement_Func001A takes nothing returns nothing
    local location p = GetUnitLoc(GetEnumUnit())
    local location pp = PolarProjectionBJ(p, 7.00, GetUnitFacing(GetEnumUnit()))
    local effect boom
    local real dmg = I2R(GetUnitUserData(GetEnumUnit()))
    local real radiustargets = 50.00
    local real radiusdmg = 120.00
    local string sfxpath = "Abilities\\Spells\\Other\\Incinerate\\FireLordDeathExplode.mdl"
    //Done with locals.
    //Done with setup.
    call SetWidgetLife( GetEnumUnit(), ( GetUnitState( GetEnumUnit(), UNIT_STATE_LIFE ) - 0.01 ) )
    call SetUnitPositionLoc( GetEnumUnit(), PolarProjectionBJ(GetUnitLoc(GetEnumUnit()), 7.00, GetUnitFacing(GetEnumUnit())) )
    set Targets = GetUnitsInRangeOfLocMatching(radiustargets, GetUnitLoc(GetEnumUnit()), Condition(function Trig_Fireball_Movement_Func001Func003002003))
    if ( Trig_Fireball_Movement_Func001Func004Func001C() ) then
        call UnitDamagePoint( GetEnumUnit(), 0.00, radiusdmg, GetLocationX(p), GetLocationY(p), dmg, true, false, ATTACK_TYPE_CHAOS, DAMAGE_TYPE_FIRE, WEAPON_TYPE_WHOKNOWS )
        set boom = AddSpecialEffectLoc( sfxpath, p )
        call RemoveUnit( GetEnumUnit() )
        call DestroyEffect(boom)
    else
    endif
    call DestroyGroup(Targets)
    call RemoveLocation(p)
    call RemoveLocation(pp)
endfunction

private function Actions takes nothing returns nothing
    call ForGroup( udg_FireBolts, function Trig_Fireball_Movement_Func001A )
endfunction

//===========================================================================
private function Init takes nothing returns nothing
    local trigger trg = CreateTrigger(  )
    call TriggerRegisterTimerEvent( trg, 0.01, true )
    call TriggerAddAction( trg, function Actions )
endfunction

endscope

//~~~~~~ End of Movement
//~~~ Ending Scopes
 
Level 11
Joined
Apr 28, 2008
Messages
696
I think, cause the global you initialized in the 2nd scope is private it can't be seen by the other scope. Test and remove the private tag. I'm not that pro in JASS but in JAVA private methods/variables can only be seen by the class they are initialized in.
 
Level 21
Joined
Dec 9, 2007
Messages
3,096
The variable Targets doesn't have to be used anywhere else.
I need a global FireBolts to work in both scopes.

Oh and is there any way to mix the scopes and keep the creation and movement separated?

Like making an init function wich triggers the initialization functions for the two different triggers?
 
Level 11
Joined
Apr 28, 2008
Messages
696
Learn vJASS and use structs there you can initialize variables as members that will only be seen in that struct and its methods. A gobal will allways be seen by every function as long it is not private. I think you can't declare two globals within the same script with the same name even if they are private. At least in Java you can't do so.

In JASS a globals is automatically moved in the front of everything else. Scopes simulate libraries and move the code right under the globals. That allows to use globals in both scopes. If you want to use a groupd variable in both scopes you can'z use a global with the same name, or it will be redeclared.

And btw I don't understand why you want to use two scopes dealing with the same spell. Can't you simple use a single one?
 
Level 15
Joined
Feb 15, 2006
Messages
851
Scopes are for simplify code, not complicate it, then you're using it wrong.

We use one scope per spell, so this should be in one scope.

You need to learn more jass, in this moment you're in thee step of doing the things by trial. I'd suggest to post this at WC3C and be open to criticism, if you want to advance fast in this topic.
 
Level 21
Joined
Dec 9, 2007
Messages
3,096
Stop until I have a heart attack...

I am not done with the fucking code, I just needed to know one thing.

Many thanks to Element_of_Water for that tutorial, it helped me a lot with this!
I did not know structs can be arrayed!
I can finaly advance in making this spell.
(It's not going to be just a damned little fire bolt!)
 
Stop until I have a heart attack...
Erm... you mean stop before you have a heart attack?

Many thanks to Element_of_Water for that tutorial, it helped me a lot with this!
I did not know structs can be arrayed!
I can finaly advance in making this spell.
(It's not going to be just a damned little fire bolt!)
You're welcome. Good luck with making the spell using a vJass indexing system!
 
Status
Not open for further replies.
Top