1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still havn't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. Don’t forget to sign up for the Hive Cup. There’s a 555 EUR prize pool. Sign up now!
    Dismiss Notice
  4. The Hive Workshop Cup contest results have been announced! See the maps that'll be featured in the Hive Workshop Cup tournament!
    Dismiss Notice
  5. The results are out! Check them out.
    Dismiss Notice
  6. The poll for Hive's 12th Concept Art Contest is up! Go cast your vote for your favourite genie!
    Dismiss Notice
  7. The raddest synthwave tracks were chosen - Check out our Music Contest #12 - Results and congratulate the winners!
    Dismiss Notice
  8. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

[JASS] Learning JASS. Last Question

Discussion in 'Triggers & Scripts' started by Starquizer, Jun 9, 2009.

  1. Starquizer

    Starquizer

    Joined:
    Mar 3, 2006
    Messages:
    1,526
    Resources:
    6
    Maps:
    1
    Spells:
    2
    Tutorials:
    3
    Resources:
    6
    Sweet Dreams :smile:
     
  2. Starquizer

    Starquizer

    Joined:
    Mar 3, 2006
    Messages:
    1,526
    Resources:
    6
    Maps:
    1
    Spells:
    2
    Tutorials:
    3
    Resources:
    6
    I don't understand this, could you explain it, plz
     
  3. Element of Water

    Element of Water

    Joined:
    Aug 3, 2008
    Messages:
    2,298
    Resources:
    5
    Spells:
    3
    Tutorials:
    1
    JASS:
    1
    Resources:
    5
    SetUnitPosition(x, y) will make the unit jump to the point nearest where you want it to go that it is able to stand on. SetUnitX(x) / SetUnitY(y) will definitely put the unit exactly where you say, even if it shouldn't be able to stand there normally.
     
  4. Starquizer

    Starquizer

    Joined:
    Mar 3, 2006
    Messages:
    1,526
    Resources:
    6
    Maps:
    1
    Spells:
    2
    Tutorials:
    3
    Resources:
    6
    Does that means that I will need two variables; one for X and another for Y instead of just one variable, which is stepPoint in my case ?
     
  5. GhostWolf

    GhostWolf

    Joined:
    Jul 29, 2007
    Messages:
    4,836
    Resources:
    2
    Tools:
    1
    Tutorials:
    1
    Resources:
    2
    How the hell do you even think about these things....................It uses x and y exactly like any other position setting function...........
     
  6. Starquizer

    Starquizer

    Joined:
    Mar 3, 2006
    Messages:
    1,526
    Resources:
    6
    Maps:
    1
    Spells:
    2
    Tutorials:
    3
    Resources:
    6
    In making an AoE spell what are the variables I need either globals or in the struct ?
     
  7. Element of Water

    Element of Water

    Joined:
    Aug 3, 2008
    Messages:
    2,298
    Resources:
    5
    Spells:
    3
    Tutorials:
    1
    JASS:
    1
    Resources:
    5
    Just work the damn thing out yourself. We don't need to guide you through step-by-step! You can't learn if you don't try.
     
  8. Starquizer

    Starquizer

    Joined:
    Mar 3, 2006
    Messages:
    1,526
    Resources:
    6
    Maps:
    1
    Spells:
    2
    Tutorials:
    3
    Resources:
    6
    I am not asking to tell me the whole script just some hints, the entire vjASS is completely new to me.
     
  9. busterkomo

    busterkomo

    Joined:
    Jun 17, 2007
    Messages:
    1,423
    Resources:
    1
    Tutorials:
    1
    Resources:
    1
    They'll give you hints you don't understand. You'll come back here and require more assistance, which results in more and more hints until they write your entire script for you. And you still won't understand it.
     
  10. Starquizer

    Starquizer

    Joined:
    Mar 3, 2006
    Messages:
    1,526
    Resources:
    6
    Maps:
    1
    Spells:
    2
    Tutorials:
    3
    Resources:
    6
    Ok, I guess I'll have to take it the hard way but thanks nontheless.
     
  11. maskedpoptart

    maskedpoptart

    Joined:
    Aug 4, 2006
    Messages:
    351
    Resources:
    1
    Spells:
    1
    Resources:
    1
    When it comes to stuff like programming, there is no "easy way". You have to learn by doing. Besides, it can be quite rewarding when you finally get something to work that you made all by yourself. You have to be willing to experiment and get your hands dirty to figure out how things work.
     
  12. Starquizer

    Starquizer

    Joined:
    Mar 3, 2006
    Messages:
    1,526
    Resources:
    6
    Maps:
    1
    Spells:
    2
    Tutorials:
    3
    Resources:
    6
    You are right programming is not easy but thanks for the hints.
     
  13. Starquizer

    Starquizer

    Joined:
    Mar 3, 2006
    Messages:
    1,526
    Resources:
    6
    Maps:
    1
    Spells:
    2
    Tutorials:
    3
    Resources:
    6
    I am trying to make the scipt for making an AoE nova, I have made a few things here.

    AoE script

    Code (vJASS):

    scope AoETemplate initializer Init
        private keyword Data
     
        globals
            private constant real TIMER_INTERVAL = 0.03
            private constant real DIST = 32
            private constant integer NOVA_SIZE = 36 // number of the Nova Units
            private constant integer UNIT_ID = 'e001' // rawcode of the Nova Unit
            private constant integer ABIL_ID = 'A001' // rawcode of the Dummy Spell
        endglobals
     
        private struct Data
            unit caster
            unit array Nova[NOVA_SIZE]
            player Owner
            real cx
            real cy
     
            static method NovaStart takes unit caster, location centre returns nothing
                local Data dat = Data.allocate()
                local integer i = 0
                local real A = 0
                local real dA = 360. / NOVA_SIZE
                local real dr = 0
                set dat.caster = caster
                set dat.Owner = GetOwningPlayer(dat.caster)
                set dat.cx = GetLocationX(centre)
                set dat.cy = GetLocationY(centre)
                loop
                    exitwhen i == NOVA_SIZE
                    set dat.Nova[i] = CreateUnit(Player(0),UNIT_ID,dat.cx,dat.cy,A)
                    set A = A + dA
                    set i = i + 1
                endloop
            endmethod
     
            static method NovaExpand takes nothing returns nothing
            endmethod
     
        endstruct
     
         private function Conditions takes nothing returns boolean
            return GetSpellAbilityId() == ABIL_ID
         endfunction
     
         private function Actions takes nothing returns nothing
            call Data.NovaStart(GetTriggerUnit(), GetSpellTargetLoc())
         endfunction
     
         private function Init takes nothing returns nothing
            local trigger t = CreateTrigger()
            call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_CAST)
            call TriggerAddCondition(t,Condition(function Conditions))
            call TriggerAddAction(t,function Actions)
         endfunction
    endscope
     


    Is it going well ?
     
  14. Eleandor

    Eleandor

    Joined:
    Aug 21, 2005
    Messages:
    3,681
    Resources:
    2
    Models:
    1
    Tutorials:
    1
    Resources:
    2
    Looks good. I'd change EVENT_PLAYER_UNIT_SPELL_CAST into EVENT_PLAYER_UNIT_SPELL_EFFECT. The "EFFECT" takes place when the spell has cost mana and started cooldown, while "CAST" still allows for some abuse...
     
  15. Starquizer

    Starquizer

    Joined:
    Mar 3, 2006
    Messages:
    1,526
    Resources:
    6
    Maps:
    1
    Spells:
    2
    Tutorials:
    3
    Resources:
    6
    solved

    script with error

    Code (vJASS):

    scope AoETemplate initializer Init
        private keyword Data
     
        globals
            private constant real TIMER_INTERVAL = 0.03
            private constant real DIST = 32.00
            private constant real NOVA_RADIUS = 288.00 // radius of the Nova
            private constant integer NOVA_SIZE = 36 // number of the Nova Units
            private constant integer UNIT_ID = 'e001' // rawcode of the Nova Unit
            private constant integer ABIL_ID = 'A001' // rawcode of the Dummy Spell
        endglobals
     
        private struct Data
            unit caster
            unit array Nova[NOVA_SIZE]
            player owner
            real cx
            real cy
     
            static method NovaStart takes unit caster, location centre returns nothing
                local Data dat = Data.allocate()
                local integer i = 0
                local real A = 0.00
                local real dA = 360.00 / NOVA_SIZE
                local real dr = 0
                set dat.caster = caster
                set dat.owner = GetOwningPlayer(dat.caster)
                set dat.cx = GetLocationX(centre)
                set dat.cy = GetLocationY(centre)
                loop
                    exitwhen i == NOVA_SIZE
                    set dat.Nova[i] = CreateUnit(dat.owner,UNIT_ID,dat.cx,dat.cy,A)
                    set A = A + dA
                    set i = i + 1
                endloop
     
            endmethod
     
            static method NovaExpand takes nothing returns nothing
                local Data dat
                local integer index = 0
                local real r
                local real rmax = NOVA_RADIUS
                local real array nux[NOVA_SIZE]
                local real array nuy[NOVA_SIZE]
                // nova expanding
                loop
                    exitwhen r == rmax
                    call SetUnitX(dat.Nova[index],nux[index])
                    call SetUnitY(dat.Nova[index],nuy[index])
                    set index = index + 1
                endloop
     
                // nova damage
            endmethod
     
        endstruct
     
         private function Conditions takes nothing returns boolean
            return GetSpellAbilityId() == ABIL_ID
         endfunction
     
         private function Actions takes nothing returns nothing
            call Data.NovaStart(GetTriggerUnit(), GetUnitLoc(GetTriggerUnit()))
         endfunction
     
         private function Init takes nothing returns nothing
            local trigger t = CreateTrigger()
            call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
            call TriggerAddCondition(t,Condition(function Conditions))
            call TriggerAddAction(t,function Actions)
         endfunction
    endscope
     


    I get error saying:
    " Line 168: Unexprcted: [AoETemplate__NOVA_SIZE] "

    Whats wrong ?



    solved too

    The nova don't expand what's wrong with my code ?

    script

    Code (vJASS):

    scope AoETemplate initializer Init
        private keyword Data
     
        globals
            private constant real TIMER_INTERVAL = 0.5
            private constant real DIST = 32.00
            private constant real NOVA_RADIUS = 512.00 // radius of the Nova
            private constant integer NOVA_SIZE = 9 // number of the Nova Units
            private constant integer UNIT_ID = 'e001' // rawcode of the Nova Unit
            private constant integer ABIL_ID = 'A001' // rawcode of the Dummy Spell
            private timer tm
        endglobals
     
        private struct Data
            unit caster
            unit array Nova[NOVA_SIZE]
            player owner
            real cx
            real cy
            static method NovaExpand takes nothing returns nothing
                local Data dat = Data.allocate()
                local integer i2 = 0
                local real r = 0
                local real dr = DIST
                local real rmax = NOVA_RADIUS
                local real array nux
                local real array nuy
                local real A = 0.00
                local real dA = 360.00 / NOVA_SIZE
     
                // nova expanding
                loop
                    exitwhen i2 == NOVA_SIZE
                    set nux[i2] = dat.cx + r * Cos(A * bj_DEGTORAD)
                    set nuy[i2] = dat.cy + r * Sin(A * bj_DEGTORAD)
                    call SetUnitX(dat.Nova[i2],nux[i2])
                    call SetUnitY(dat.Nova[i2],nux[i2])
                    set r = r + dr
                    set A = A + dA
                    set i2 = i2 + 1
                endloop
     
                // nova damage
            endmethod
            static method NovaStart takes unit caster, location centre returns nothing
                local Data dat = Data.allocate()
                local integer i = 0
                local real A = 0.00
                local real dA = 360.00 / NOVA_SIZE
                set dat.caster = caster
                set dat.owner = GetOwningPlayer(dat.caster)
                set dat.cx = GetLocationX(centre)
                set dat.cy = GetLocationY(centre)
                loop
                    exitwhen i == NOVA_SIZE
                    set dat.Nova[i] = CreateUnit(dat.owner,UNIT_ID,dat.cx,dat.cy,A)
                    set A = A + dA
                    set i = i + 1
                endloop
     
                call TimerStart(tm,TIMER_INTERVAL,true,function Data.NovaExpand)
     
            endmethod
     
        endstruct
     
         private function Conditions takes nothing returns boolean
            return GetSpellAbilityId() == ABIL_ID
         endfunction
     
         private function Actions takes nothing returns nothing
            call Data.NovaStart(GetTriggerUnit(), GetUnitLoc(GetTriggerUnit()))
         endfunction
     
         private function Init takes nothing returns nothing
            local trigger t = CreateTrigger()
            call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
            call TriggerAddCondition(t,Condition(function Conditions))
            call TriggerAddAction(t,function Actions)
            set tm = CreateTimer()
         endfunction
    endscope
     


     
    Last edited: Jul 5, 2009
  16. Starquizer

    Starquizer

    Joined:
    Mar 3, 2006
    Messages:
    1,526
    Resources:
    6
    Maps:
    1
    Spells:
    2
    Tutorials:
    3
    Resources:
    6
    When writting
    Code (vJASS):

    struct Str
    unit U
    location P
    real R
    real A
    method takes m1 takes unit u, location p, real r, real a returns Str
              local Str S = Str.allocate()
              set S.U = u
              set S.P = p
              set S.R = r
              set S.A = a
              return S
    endmethod
     


    What is the value of S when I say return S?

    And if I want to use the value of the struct S in another method or function do I write
    Code (vJASS):

    method m2 takes nothing returns nothing
              local Str S = Str.allocate
              local unit UNIT = S.U
              local location LOC = S.P
              local real RADIUS = S.R
              local real ANGLE = S.A
    endmethod
    endstruct
     


    will the values of m2 local variables be the same as in m1 ?
     
  17. Eleandor

    Eleandor

    Joined:
    Aug 21, 2005
    Messages:
    3,681
    Resources:
    2
    Models:
    1
    Tutorials:
    1
    Resources:
    2
    A unique value between 1 and 8190 (can be higher if you explicitly need more). Each struct you create corresponds with such a value. When a struct variable is destroyed, the index is available again. For example:

    set s = Str.create() // s is 1
    set s = Str.create() // s is 2
    set d = Str.create() // d is 3
    call s.destroy() // the index "2" is available again
    set d = Str.create() // d is 2

    Note that there are 2 leaks here, since we never destroy the first S we created and the first d we created. Thus, indices 1 and 3 are still in use and cannot be recycled.

    No. Str.allocate() allocates new memory for U,P,R,A variables. When you use Str.allocate(), the variables themselves aren't initialized yet.
    Thus, in m2 when you use Str.allocate(), U,P,R,A are still uninitialized. And thus UNIT, LOC, RADIUS and ANGLE too will be uninitialized because S.U, S.P, S.R, S.A don't have a value yet.

    In m1, you allocate new memory for your U, P, R, A variables, and you change their values to u, p, r, a.
     
  18. Starquizer

    Starquizer

    Joined:
    Mar 3, 2006
    Messages:
    1,526
    Resources:
    6
    Maps:
    1
    Spells:
    2
    Tutorials:
    3
    Resources:
    6
    That means that in order to transfer the value of m1 to m2 I will need another variable of Str type but it must be global in that case. Right or Wrong ?
     
  19. Starquizer

    Starquizer

    Joined:
    Mar 3, 2006
    Messages:
    1,526
    Resources:
    6
    Maps:
    1
    Spells:
    2
    Tutorials:
    3
    Resources:
    6
    script
    Code (vJASS):
    scope AoETemplate initializer Init
        private keyword Data
        globals
            private constant real TIMER_INTERVAL = 0.02
            private constant real DIST = 32.00
            private constant real NOVA_RADIUS = 512.00 // radius of the Nova
            private constant integer NOVA_SIZE = 64 // number of the Nova Units
            private constant integer UNIT_ID = 'e001' // rawcode of the Nova Unit
            private constant integer ABIL_ID = 'A001' // rawcode of the Dummy Spell
            private timer tm
            private Data array temp_dat
            private integer index = 0
        endglobals
        private struct Data
            unit caster
            unit array Nova[NOVA_SIZE]
            player owner
            static real cx // cx: Centre X
            static real cy // cy: Centre Y
            static real r = 32.00 // current radius of the nova. initial value = 32.00
            static real dr = DIST // radius increment
            static real array nux[NOVA_SIZE]   // nux: Nova Unit X
            static real array nuy[NOVA_SIZE]   // nuy: Nova Unit Y
            static method NovaExpand takes nothing returns nothing
                local Data dat
                local integer i = 0
                local real rmax = NOVA_RADIUS
                local real A = 0
                local real dA = 360.00 / NOVA_SIZE
    //      nova expanding
                loop
                    exitwhen i >= NOVA_SIZE
                    set dat = temp_dat[i]
                    set dat.nux[i] = Data.cx + Data.r * Cos( A * bj_DEGTORAD )
                    set dat.nuy[i] = Data.cy + Data.r * Sin( A * bj_DEGTORAD )
                    call SetUnitX( dat.Nova[i] , Data.nux[i] )
                    call SetUnitY( dat.Nova[i] , Data.nuy[i] )
                    set i = i + 1
                    set A = A + dA
                endloop
               
                if Data.r >= rmax then
                    call dat.destroy()
                endif
               
                set Data.r = Data.r + Data.dr
            endmethod
            static method NovaCreate takes unit caster, location centre returns Data
                local Data dat = Data.allocate()
                local integer i = 0
                local real A = 0.00
                local real dA = 360.00 / NOVA_SIZE
                set dat.caster = caster
                set dat.owner = GetOwningPlayer(dat.caster)
                set Data.cx = GetLocationX(centre)
                set Data.cy = GetLocationY(centre)
                loop
                    exitwhen i >= NOVA_SIZE
                    set dat.Nova[i] = CreateUnit( dat.owner , UNIT_ID , dat.cx , dat.cy , A )
                    set A = A + dA
                    set i = i + 1
                endloop
               
                if index == 0 then
                    call TimerStart(tm,TIMER_INTERVAL,true,function Data.NovaExpand)
                endif
               
                set temp_dat[index] = dat            
                set index = index + 1
                return dat
            endmethod
            method onDestroy takes nothing returns nothing
                local integer i = 0
                call PauseTimer(tm)
                loop
                    exitwhen i >= NOVA_SIZE
                    call KillUnit(.Nova[i])
                    set .Nova[i] = null
                    set i = i + 1
                endloop
                set index = index - 1
            endmethod
        endstruct
         private function Conditions takes nothing returns boolean
            return GetSpellAbilityId() == ABIL_ID
         endfunction
         private function Actions takes nothing returns nothing
            call Data.NovaCreate(GetTriggerUnit(), GetUnitLoc(GetTriggerUnit()))
         endfunction
         private function Init takes nothing returns nothing
            local trigger t = CreateTrigger()
            call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
            call TriggerAddCondition(t,Condition(function Conditions))
            call TriggerAddAction(t,function Actions)
            set tm = CreateTimer()
         endfunction
    endscope


    The nova expands to infinity and after a few seconds the game craches, I tried to destroy the struct but why onDestroy function hasn't been called ?

    (Please, help me and don't ignore me this time)
     
  20. Silvenon

    Silvenon

    Joined:
    Nov 22, 2006
    Messages:
    1,233
    Resources:
    1
    Tutorials:
    1
    Resources:
    1
    I didn't have time to look through the whole thing, but it seems to me like you're only destroying one "dat" when you should put your if/then/else in the loop to check every struct.

    I don't get this thread. So you're basically reading Vexorian's jasshelper manual and posting here immediately when you don't understand something? Why don't you just take your time and read those stuff multiple times? It's how complicated manuals should be read anyways.