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. The Lich King demands your service! We've reached the 19th edition of the Icon Contest. Come along and make some chilling servants for the one true king.
    Dismiss Notice
  4. The 4th SFX Contest has started. Be sure to participate and have a fun factor in it.
    Dismiss Notice
  5. The poll for the 21st Terraining Contest is LIVE. Be sure to check out the entries and vote for one.
    Dismiss Notice
  6. The results are out! Check them out.
    Dismiss Notice
  7. Don’t forget to sign up for the Hive Cup. There’s a 555 EUR prize pool. Sign up now!
    Dismiss Notice
  8. The Hive Workshop Cup contest results have been announced! See the maps that'll be featured in the Hive Workshop Cup tournament!
    Dismiss Notice
  9. 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] Random array problem

Discussion in 'Triggers & Scripts' started by Saishy, Jun 19, 2009.

  1. Saishy

    Saishy

    Joined:
    Mar 23, 2008
    Messages:
    947
    Resources:
    0
    Resources:
    0
    I installed jass newgen pack in a new computer and started working in my map, when I tried saving it:

    Line 6166: Unexpected: [5]

    Code (vJASS):
    scope Sprenger initializer in_Sprenger

    globals
        private group array sgroup[10]
        private integer array dmg[10]
        private real array sx[10]
        private real array sy[10]
        private player tplayer
        private unit sunit
    endglobals

    //===========================================================================

    private function Sprenger_Conditions takes nothing returns boolean
        return (GetSpellAbilityId() == 'A043')
    endfunction

    //===========================================================================

    private function Sprenger_Group_Cond takes nothing returns boolean
        return ( (IsUnitEnemy(GetFilterUnit(), tplayer)) and GetUnitState(GetFilterUnit(), UNIT_STATE_LIFE) > 0.449 )
    endfunction

    //===========================================================================

    function Sprenger_Destroy_Group takes integer i returns nothing
        local unit u
            loop
                set u = FirstOfGroup(sgroup[i])
                call GroupRemoveUnit(sgroup[i], u)
                call RemoveUnit(u)
                exitwhen u == null
            endloop
        call DestroyGroup(sgroup[i])
        set sgroup[i] = null
        set dmg[i] = 0
        set sx[i] = 0
        set sy[i] = 0
    endfunction

    //===========================================================================

    function Sprenger_Effects takes nothing returns nothing
        local unit trap = GetEnumUnit()
        local real x = GetUnitX(trap)
        local real y = GetUnitY(trap)
        call UnitApplyTimedLife(CreateUnit(GetOwningPlayer(trap), 'h014', x, y, 0), 'BTLF', 2.00)
        call UnitAddAbility(trap, 'A04F')
        call IssueTargetOrderById(trap, 852487, sunit)
        call UnitRemoveAbility(trap, 'Apiv')
        call UnitAddAbility(trap, 'Aloc')
    endfunction

    //===========================================================================

    function Sprenger_Working takes integer i returns nothing
        local group targetgroup = CreateGroup()
        local unit dummy
        local unit target
        local player tp

        set tplayer = GetOwningPlayer(FirstOfGroup(sgroup[i]))
        set tp = tplayer
        call GroupEnumUnitsInRange(targetgroup, sx[i], sy[i], 200, Condition(function Sprenger_Group_Cond))
        set sunit = GroupPickRandomUnit(targetgroup)
        set target = sunit
        call GroupClear(targetgroup)
        call ForGroup(sgroup[i], function Sprenger_Effects)
        call SetUnitX(target, sx[i])
        call SetUnitY(target, sy[i])
        call PauseUnit(target, true)
        set dummy = CreateUnit(tplayer, 'h00E', sx[i], sy[i], 0)
        call UnitApplyTimedLife(dummy, 'BTLF', 5.00)
        call UnitAddAbility(dummy, 'A04E')
        call SetUnitAbilityLevel(dummy, 'A04E', dmg[i])
       
        call DestroyGroup(targetgroup)
        set targetgroup = null
        set sunit = null
        call PolledWait2(1.0)
        call UnitApplyTimedLife(CreateUnit(tp, 'h014', sx[i], sy[i], 0), 'BTLF', 2.00)
        call PolledWait2(1.0)
        call IssuePointOrder(dummy, "blizzard", sx[i], sy[i])
        call PolledWait2(1.0)
        call UnitApplyTimedLife(CreateUnit(tp, 'h015', sx[i], sy[i], 0), 'BTLF', 3.00)
        call UnitApplyTimedLife(CreateUnit(tp, 'h016', sx[i], sy[i], 0), 'BTLF', 2.00)
        call PauseUnit(target, false)
        set tp = null
        set target = null
        set dummy = null
        call Sprenger_Destroy_Group(i)
    endfunction

    //===========================================================================

    private function Sprenger_Group takes nothing returns integer
        local integer i = 0
       
        loop
            if sgroup[i] == null then
                set sgroup[i] = CreateGroup()
                return i
                set i = 9
            endif
            set i = i + 1
            exitwhen i >= 9
        endloop
       
        return -1
    endfunction

    //===========================================================================

    private function Sprenger_Actions takes nothing returns nothing
        local unit u
        local unit caster = GetTriggerUnit()
        local location temppoint = GetUnitLoc(caster)
        local location array sp[5]
        local integer a = 0
        local integer i
        local player p = GetOwningPlayer(caster)
        local integer ts = GetPlayerId(p)+1
       
        set i = Sprenger_Group()
        if i >= 0 then
            set dmg[i] = GetUnitAbilityLevel(caster, 'A043')
            set sx[i] = GetUnitX(caster)
            set sy[i] = GetUnitY(caster)
            loop
                exitwhen a > 4
                set sp[a] = PolarProjectionBJ(temppoint, 250.00, ( 90.00 + ( I2R(a) * 72.00 ) ))
                set u = CreateUnitAtLoc(p, 'h012', sp[a], 0 )
                call SetUnitUserData(u, i)
                call GroupAddUnit(sgroup[i], u)
                set a = a + 1
                call RemoveLocation(sp[a])
                set sp[a] = null
            endloop
        endif

        set u = null
        set p = null
        call RemoveLocation(temppoint)
        set temppoint = null
    endfunction

    //===========================================================================
    private function in_Sprenger takes nothing returns nothing
        local trigger t_Sprenger = CreateTrigger()
        call TriggerRegisterAnyUnitEventBJ( t_Sprenger, EVENT_PLAYER_UNIT_SPELL_FINISH )
        call TriggerAddCondition( t_Sprenger, Condition( function Sprenger_Conditions ) )
        call TriggerAddAction( t_Sprenger, function Sprenger_Actions )
        set t_Sprenger = null
    endfunction

    endscope


    I didn't tested it in my house yest, but I updated the jass newgen version there also.
     
  2. Silvenon

    Silvenon

    Joined:
    Nov 22, 2006
    Messages:
    1,233
    Resources:
    1
    Tutorials:
    1
    Resources:
    1
    You can't declare a local like that. Only dynamic arrays and array struct members can be declared like that.

    When you're declaring a local array, you cannot set the number.
     
  3. Saishy

    Saishy

    Joined:
    Mar 23, 2008
    Messages:
    947
    Resources:
    0
    Resources:
    0
    Strange o_O
    Why this always worked til this version?

    So, can I just leave without the number and nothing will chance?
     
  4. Silvenon

    Silvenon

    Joined:
    Nov 22, 2006
    Messages:
    1,233
    Resources:
    1
    Tutorials:
    1
    Resources:
    1
    It did? Well, I don't see the point in it. You see, in GUI you have to specify how many array members you're going to have, because GUI automatically assigns null to those values (to integers it assigns "0", to boolean "false" etc.), but JASS doesn't do that, you have to do that manually.

    Yes, there is no point in having to specify the number of array members if they won't have a value anyway.

    When Vex was explaining dynamic arrays, he specifically said that for them you have to specify the number of array members, which clearly means that you otherwise don't have to.

    One question for you: why are some of your variables named like
    sp[a]
    ? To tell you the truth, that scares me a bit :)
     
  5. Cokemonkey11

    Cokemonkey11

    Wurst Reviewer

    Joined:
    May 9, 2006
    Messages:
    3,240
    Resources:
    18
    Tools:
    1
    Maps:
    5
    Spells:
    3
    Tutorials:
    2
    JASS:
    7
    Resources:
    18
    sp[a] is what it says, but the jass tag is broken.
     
  6. Saishy

    Saishy

    Joined:
    Mar 23, 2008
    Messages:
    947
    Resources:
    0
    Resources:
    0
    Thanks ^^