• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[JASS] Crazy syntax

Status
Not open for further replies.
Level 9
Joined
Jun 7, 2008
Messages
440
I have this little part of a trigger which is really simple. But for some reason I get a syntax. Can anyone help me out?
JASS:
function Trig_Lightning_Actions takes nothing returns nothing
    local unit cast = GetTriggerUnit()
    local real x = 0
    local real y = 0
    local unit dumb
    local integer i = 1
    local integer o = 8
    loop
      exitwhen i>o
      set i = i + 1
      set x = GetUnitX(cast) + 500 * Cos(x + 45.*bj_DEGTORAD)
      set y = GetUnitY(cast) + 500 * Sin(y + 45.*bj_DEGTORAD)
      set dumb = CreateUnit(GetOwningPlayer(cast), 'h008', x, y, 0.)
      call UnitAddAbility(dumb, 'A01H')
      call IssueTargetOrder(dumb, "chainlightning", cast)
      call UnitApplyTimedLife(dumb, 'BTLF', 10) // This is my syntax
    endloop
    set cast = null
    set dumb = null
endfunction

Also, if I wanted to create an additional dummy unit and give it a different spell with a different expiration timer, could I possibly do this inside the loop? Or would I have to do another loop? Sounds like a dumb question :p Thanks for the help.
 
Level 9
Joined
Jun 7, 2008
Messages
440
Indeed it does look like that. I really don't understand what the problem is. As well, I get another syntax but this time with this:
JASS:
function Trig_Lightning_Actions takes nothing returns nothing
    local unit cast = GetTriggerUnit()
    local real x = 0
    local real y = 0
    local unit array dumb
    local integer i = 1
    local integer o = 8
    loop
      exitwhen i>o
      set i = i + 1
      set x = GetUnitX(cast) + 500 * Cos(x + 45.*bj_DEGTORAD)
      set y = GetUnitY(cast) + 500 * Sin(y + 45.*bj_DEGTORAD)
      set dumb[0] = CreateUnit(GetOwningPlayer(cast), 'h008', x, y, 0.)
      set dumb[1] = CreateUnit(GetOwningPlayer(cast), 'h008', x, y, 0.)
      call UnitAddAbility(dumb[0], 'A01H')
      call IssueTargetOrder(dumb[0], "chainlightning", cast)
      call UnitApplyTimedLife(dumb[0], 'BTLF', 10)
      call UnitAddAbility(dumb[1], 'A01Z')
      call IssueTargetOrder(dumb[1], "stomp")
      call UnitApplyTimedLife(dumb[1], 'BTLF', 3) // This is my syntax now
    endloop
    set cast = null
    set dumb[0] = null
    set dumb[1] = null
endfunction
 
Not related to your question, but the code you posted does not really achieve the effect I think you are trying to get, which i think is 8 lightnig bolts in a perfect circle around the caster. This code will achieve that effect (and I've more or less optimized it):

JASS:
function Trig_Lightning_Actions takes nothing returns nothing
    local unit cast = GetTriggerUnit()
    local player p = GetTriggerPlayer()
    local unit dumb
    local real x1 = GetUnitX(cast)
    local real y1 = GetUnitY(cast)
    local real x2
    local real y2
    local integer i = 1
    loop
        set x2 = x1 + 500.*Cos(i*45.*bj_DEGTORAD)
        set y2 = y2 + 500.*Sin(i*45.*bj_DEGTORAD)
        set dumb = CreateUnit(p, 'h008', x2, y2, 0.)
        call UnitAddAbility(dumb, 'A01H')
        call IssueTargetOrder(dumb, "chainlightning", cast)
        call UnitApplyTimedLife(dumb, 'BTLF', 10)
        set dumb = CreateUnit(p, 'h008', x2, y2, 0.)
        call UnitAddAbility(dumb, 'A01Z')
        call IssueImmediateOrder(dumb, "stomp")
        call UnitApplyTimedLife(dumb, 'BTLF', 3)
        exitwhen i == 8
        set i = i + 1
    endloop
    set cast = null
    set dumb = null
endfunction

And if you have NewGen or another vJass compiler, that will be 100% optimized as:

JASS:
scope Lightning
 
globals
    private real array cos
    private real array sin
    private unit dum
endglobals
 
    private function Strike takes unit cast returns nothing
        local real    x = GetUnitX(cast)
        local real    y = GetUnitY(cast)
        local integer i = 0
        //GetTriggerPlayer, in response to a spell effect, returns the owner of the triggering
        //unit.  It's pretty cool.  Players do not leak handles, so don't set them to null.
        local player  p = GetTriggerPlayer()
        loop
            set dum = CreateUnit(p      ,'h008',x + cos[i],y + sin[i],0.)
            call UnitAddAbility(dum     ,'A01H')
            call IssueTargetOrder(dum   ,"chainlightning",cast)
            call UnitApplyTimedLife(dum ,'BTLF',10.)
            set dum = CreateUnit(p      ,'h008',x + cos[i],y + sin[i],0.)
            call UnitAddAbility(dum     ,'A01Z')
            call IssueImmediateOrder(dum,"stomp")
            call UnitApplyTimedLife(dum ,'BTLF',3.)
            exitwhen i == 7
            set i = i + 1
        endloop
    endfunction
 
    private function Setup takes nothing returns boolean
        //Subroutines that take parameters which would otherwise need nulling are proven to
        //be faster than actually nulling locally-declared variables.
        call Strike(GetTriggerUnit())
        return false
    endfunction
 
    private function Init takes nothing returns nothing
        local integer i = 8
        //Locally-created triggers, unless you plan to destroy them, don't need nullification.
        //In the case of spells like this one, you almost never want to destroy the trigger,
        //so don't nullify it.
        local trigger t = CreateTrigger()
        //I've learned that using Conditions instead of actions results in slightly improved
        //code performance.
        call TriggerAddCondition(t,Condition(function Setup))
        //Initializing polar projections to array variables is always more effective - if it
        //can be done.
        loop
            set cos[i - 1] = 500.*Cos(i*45.*bj_DEGTORAD)
            set sin[i - 1] = 500.*Sin(i*45.*bj_DEGTORAD)
            set i = i - 1
            exitwhen i == 0
        endloop
        //the BJ "Any Unit Spell Effect" registers four useless extra events, which allocates
        //a little extra memory.  While the difference is insignificant, I included the proper
        //spell registry for this demonstration.
        loop
            call TriggerRegisterPlayerUnitEvent(t,Player(i),EVENT_PLAYER_UNIT_SPELL_EFFECT,null)
            exitwhen i = 11
            set i = i + 1
        endloop
        //If, however, you actually want to register spells for Neutral Passive, Neutral Victim,
        //Neutral Aggressive and Neutral Extra (or are lazy/rushed), just use the BJ function.
    endfunction
 
endscope
 
Last edited:
Level 9
Joined
Jun 7, 2008
Messages
440
It seems that I somehow accidently fixed the error, as it doesnt happen anymore. The only thing i know that the syntax said this:

Code:
1 Compile error 

Line x 

     call IssueTargetOrder(dumb[0], "chainlightning", cast)

I really don't know what I did. Sorry I can be of no further help. Yes originally I wanted it so that 8 dummy units set around a circle. Pharaoh_ helped me with this, and this is what I have:
JASS:
function Trig_Pacifier_Copy_Actions takes nothing returns nothing
    local unit cast = GetTriggerUnit()
    local real x = GetUnitX(cast)
    local real y = GetUnitY(cast)
    local real distx
    local real disty
    local unit array dumb
    local integer i = 1
    local integer o = 8
    loop
      exitwhen i>o
      set distx = x + 500 * Cos(i * 360/8 * bj_DEGTORAD)
      set disty = y + 500 * Sin(i * 360/8 * bj_DEGTORAD)
      set dumb[0] = CreateUnit(GetOwningPlayer(cast), 'h008', distx, disty, 0.)
      set dumb[1] = CreateUnit(GetOwningPlayer(cast), 'h008', distx, disty, 0.)
      call UnitAddAbility(dumb[0], 'A01H')
      call IssueTargetOrder(dumb[0], "chainlightning", cast)
      call UnitApplyTimedLife(dumb[0], 'BTLF', 10)
      call UnitAddAbility(dumb[1], 'A01Z')
      call IssueImmediateOrder(dumb[1], "stomp")
      call UnitApplyTimedLife(dumb[1], 'BTLF', 4)
      set i = i + 1
    endloop
    set cast = null
    set dumb[0] = null
    set dumb[1] = null
endfunction

As to the original problem, I guess it is solved - though I know not what I did. Thanks for all the help. +rep
 
Status
Not open for further replies.
Top