• 🏆 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!

[Solved] Cannot assign a struct array's index

Status
Not open for further replies.
Level 1
Joined
Feb 8, 2011
Messages
3
I found a system for a custom birth animation for structures in an old thread here on the Hive, but while it seems to work fine in the test map, it's broken when I import it. Jasshelper gives me the error "cannot assign a struct array's index" and picks this line:

JASS:
 set Dummy[id] = CreateUnit(GetTriggerPlayer(), udg_Dummy, GetUnitX(u), GetUnitY(u), 0.00)

Here's the entire system:

JASS:
library DemonBirth initializer Init

    globals
        unit array Dummy
    endglobals

    private function Create takes nothing returns boolean
        local unit u = GetTriggerUnit()
        local integer id
        local integer index = 0
        if GetUnitAbilityLevel(u, udg_Ability) > 0 then
            set id = GetUnitUserData(u)
            set Dummy[id] = CreateUnit(GetTriggerPlayer(), udg_Dummy, GetUnitX(u), GetUnitY(u), 0.00)
            loop
                exitwhen index > udg_Array_Size
                    if GetUnitTypeId(u) == udg_Building[index] then
                        call SetUnitTimeScale(Dummy[id], udg_Animation_Length / udg_Time[index])
                    endif
                set index = index + 1
            endloop
            call SetUnitVertexColor(u, 0, 0, 0, 0)
        endif
        set u = null
        return false
    endfunction
   
    private function End takes nothing returns boolean
        local unit u = GetTriggerUnit()
        local integer id
        if GetUnitAbilityLevel(u, udg_Ability) > 0 then
            set id = GetUnitUserData(u)
            call RemoveUnit(Dummy[id])
            set Dummy[id] = null
            call SetUnitVertexColor(u, 255, 255, 255, 255)
        endif
        set u = null
        return false
    endfunction
   
    private function Death takes nothing returns boolean
        local unit u = GetTriggerUnit()
        local integer id
        if GetUnitAbilityLevel(u, udg_Ability) > 0 then
            set id = GetUnitUserData(u)
            if Dummy[id] != null then
                call SetUnitVertexColor(Dummy[id], 0, 0, 0, 0)
                call RemoveUnit(Dummy[id])
            endif
        endif
        set u = null
        return false
    endfunction

    private function Init takes nothing returns nothing
        local trigger t1 = CreateTrigger()
        local trigger t2 = CreateTrigger()
        local trigger t3 = CreateTrigger()
        local integer index = 0
        loop
            call TriggerRegisterPlayerUnitEvent(t1, Player(index), EVENT_PLAYER_UNIT_CONSTRUCT_START, null)
            call TriggerRegisterPlayerUnitEvent(t2, Player(index), EVENT_PLAYER_UNIT_CONSTRUCT_FINISH, null)
            call TriggerRegisterPlayerUnitEvent(t3, Player(index), EVENT_PLAYER_UNIT_DEATH, null)
            set index = index + 1
            exitwhen index == bj_MAX_PLAYER_SLOTS
        endloop
        call TriggerAddCondition(t1, function Create)
        call TriggerAddCondition(t2, function End)
        call TriggerAddCondition(t3, function Death)
        set t1 = null
        set t2 = null
        set t3 = null
    endfunction

endlibrary
 
I'm not sure if the the Dummy unit array is even needed. If you know some jass you could try remove it completly and replace respective parts in code.

Else, do you have a Dummy struct maybe? A simple solution might be just to make the dummy private.

unit array Dummy -> private unit array Dummy
^This would mean it can't come in conflict anymore with variables that have the same name outside the DemonBirth library
 
Status
Not open for further replies.
Top