• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] Random array problem

Status
Not open for further replies.
Level 12
Joined
Mar 23, 2008
Messages
942
I installed jass newgen pack in a new computer and started working in my map, when I tried saving it:

Line 6166: Unexpected: [5]

local location array sp[5]

JASS:
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.
 
Level 13
Joined
Nov 22, 2006
Messages
1,260
Strange o_O
Why this always worked til this version?

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.

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

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 :)
 
Level 12
Joined
Mar 23, 2008
Messages
942
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 :)
Thanks ^^
 
Status
Not open for further replies.
Top