• 🏆 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] Scope

Status
Not open for further replies.
Level 8
Joined
Jul 28, 2008
Messages
211
I started with scopes today and i wanted to practice so i made something. But it doesn't work. Why?

JASS:
scope vars
function init takes nothing returns nothing
    set target = GetSpellTargetUnit()
    set caster = GetSpellAbilityUnit()
    set x = GetUnitX(target)
    set y = GetUnitY(target)
    set c = GetUnitLoc(caster)
    set angle = GetUnitFacing(caster)
endfunction
endscope

Thx!
 
Level 8
Joined
Jul 28, 2008
Messages
211
could u explain a bit? im kinda noob at this xD

EDIT: I did that and it still doesn't work. Here's the scrip now

JASS:
scope vars initializer InitTrig_Spell

function init takes nothing returns nothing
    set target = GetSpellTargetUnit()
    set caster = GetSpellAbilityUnit()
    set x = GetUnitX(target)
    set y = GetUnitY(target)
    set c = GetUnitLoc(caster)
    set angle = GetUnitFacing(caster)
endfunction
endscope
 
Level 12
Joined
Dec 10, 2008
Messages
850
All triggers in JASS need an init function, or they wont work properly (I think libarys are exempt from this rule sometimes though). This is a basic init function that you'll find in alot of JASS spells (Atleast the one I use anyway)
JASS:
    private function Init takes nothing returns nothing
        local trigger I = CreateTrigger()
        call TriggerRegisterAnyUnitEventBJ(I,EVENT_PLAYER_UNIT_SPELL_CAST)
        call TriggerAddCondition(I,Condition(function Conditions))
        call TriggerAddAction(I,function Actions)
        set I = null
    endfunction
Copy that, change the scope part to look like this
JASS:
scope Vars initializer Init

Its best you reserve using "Init" as your initializer function, and call everything else something diffrent like Actions and Conditions

Also, whatever your main part is named (the actions, what it does), be sure to change the TriggerAddAction part to your action functions name, same goes for the Condition. If you dont have a condition, then remove the TriggerAddCondition line. If it isnt made for a spell, then you'll need a diffrent event line too.

It should work now.
 
Last edited:
Level 28
Joined
Mar 25, 2008
Messages
2,955
A scope is like a wrapper, inside a scope you can name handles as the same as in any other scope as long as the scope has another name.

Your initTrig would look like this
JASS:
   private function InitTrig takes nothing returns nothing
        local trigger t = CreateTrigger()
        call TriggerRegisterAnyUnitEventBJ(t, blah)
        call TriggerAddCondition(t, Condition(function Conditions))
        call TriggerAddAction(t, function Actions)
        set t = null
    endfunction

The name of the initializer has to be the same as the init trigger

For I am also just learning jass, I am not that expierienced ^.^, so that's almost all I can tell about scopes.. maybe a bit more


//edit: aww beat me to it
 
Level 11
Joined
Feb 22, 2006
Messages
752
Um, you dont need inittrigs with vjass. You could do this just fine:

JASS:
scope A initializer init
private function init takes nothing returns nothing
endfunction
endscope

Scopes don't even need initializers.

And by "it doesnt work" what do you mean? If it doesn't compile, then are you sure you declared your variables (target, etc.) as globals?

And GetSpellTargetUnit() and GetSpellAbilityUnit(), and every other event response function don't work inside initializers. They'll only work inside trigger actions or conditions. Maybe you want something like this:

JASS:
scope vars initializer init
globals
    private unit target
    private unit caster
    private real x
    private real y
    private location c
    private real angle
endglobals
private function actions takes nothing returns nothing
    set target = GetSpellTargetUnit()
    set caster = GetSpellAbilityUnit()
    set x = GetUnitX(target)
    set y = GetUnitY(target)
    set c = GetUnitLoc(caster)
    set angle = GetUnitFacing(caster)
endfunction
private function init takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddAction(t, function actions)
endfunction
endscope
 
Level 8
Joined
Jul 28, 2008
Messages
211
JASS:
scope vars initializer Init
globals
     constant integer id = 'spel'
     private unit target
     private real x
     private real y
     private unit caster
     private location c
     private real angle
endglobals
private function actions takes nothing returns nothing
    set target = GetSpellTargetUnit()
    set caster = GetSpellAbilityUnit()
    set x = GetUnitX(target)
    set y = GetUnitY(target)
    set c = GetUnitLoc(caster)
    set angle = GetUnitFacing(caster)
endfunction
private function Init takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddAction(t, function actions)
endfunction
endscope
Still doesn't work. It says syntax error (for scope vars) and statement outside of function for all others. And it also says that those varialbes are undeclared (in actions).
 
Status
Not open for further replies.
Top