• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

vJass trigger Issue - Can't seem to fix it

Status
Not open for further replies.
Level 3
Joined
Feb 20, 2007
Messages
32
Hey there - it's been a really long time since I've been in the coding loop and I've apparantly gotten pritty rusty. Anyways I have a bit of code I'm working on that refuses to work correctly.

The idea was to have an array so each of the four players could each 'target' a unit. However, whenever any player selects a unit it overwrites the other players selections.

Well here's my code:
JASS:
struct PLAYER_TARGET_DATA
    unit TARGET
    playercolor COLOR
endstruct

globals
    PLAYER_TARGET_DATA array SYSTEM_PTD[4]
endglobals

function ENGINE_TARGET_SYSTEM_HANDLER_DES takes nothing returns nothing
    local player p = GetTriggerPlayer()
    local unit u = GetTriggerUnit()
    local PLAYER_TARGET_DATA ptd = SYSTEM_PTD[GetPlayerId(p)]
    
    call SetUnitColor(ptd.TARGET, ptd.COLOR)
    set ptd.COLOR = null
    set ptd.TARGET = null
endfunction

function ENGINE_TARGET_SYSTEM_HANDLER takes nothing returns nothing
    local player p = GetTriggerPlayer()
    local unit u = GetTriggerUnit()
    local player o = GetOwningPlayer(u)
    local PLAYER_TARGET_DATA ptd = SYSTEM_PTD[GetPlayerId(p)]
    
    
    if(ptd.TARGET != null)then
        call SetUnitColor(ptd.TARGET, ptd.COLOR)
        set ptd.COLOR = null
    endif
    
    if(o != p)then
        set ptd.TARGET = u
        set ptd.COLOR = GetPlayerColor(o)
        if(GetLocalPlayer() == p)then
            call SetUnitColor(u, GetPlayerColor(p))
        endif
    endif
endfunction

function ENGINE_TARGET_SYSTEM_INIT takes nothing returns nothing
    local trigger ENGINE_PLAYER_SELECT = CreateTrigger()
    local trigger ENGINE_PLAYER_DESELECT = CreateTrigger()
    
    call TriggerRegisterPlayerUnitEvent(ENGINE_PLAYER_SELECT, Player(0), EVENT_PLAYER_UNIT_SELECTED, null)
    call TriggerRegisterPlayerUnitEvent(ENGINE_PLAYER_SELECT, Player(1), EVENT_PLAYER_UNIT_SELECTED, null)
    call TriggerRegisterPlayerUnitEvent(ENGINE_PLAYER_SELECT, Player(2), EVENT_PLAYER_UNIT_SELECTED, null)
    call TriggerRegisterPlayerUnitEvent(ENGINE_PLAYER_SELECT, Player(3), EVENT_PLAYER_UNIT_SELECTED, null)
    call TriggerAddAction(ENGINE_PLAYER_SELECT, function ENGINE_TARGET_SYSTEM_HANDLER)
    
    call TriggerRegisterPlayerUnitEvent(ENGINE_PLAYER_DESELECT, Player(0), EVENT_PLAYER_UNIT_DESELECTED, null)
    call TriggerRegisterPlayerUnitEvent(ENGINE_PLAYER_DESELECT, Player(1), EVENT_PLAYER_UNIT_DESELECTED, null)
    call TriggerRegisterPlayerUnitEvent(ENGINE_PLAYER_DESELECT, Player(2), EVENT_PLAYER_UNIT_DESELECTED, null)
    call TriggerRegisterPlayerUnitEvent(ENGINE_PLAYER_DESELECT, Player(3), EVENT_PLAYER_UNIT_DESELECTED, null)
    call TriggerAddAction(ENGINE_PLAYER_DESELECT, function ENGINE_TARGET_SYSTEM_HANDLER_DES)
endfunction

I honestly can't spot the error, although my logical debugging ability has been blown up after nearly a year without coding.

Nice to see you all again ;P and thanks for the help.

-Blackroot.
 
Level 3
Joined
Feb 20, 2007
Messages
32
D'oh! It was partially working so the thought that the variable wasn't initialized never occured. >.<.

I feel alot dumber now ;P. Thank you for the help!
 
Status
Not open for further replies.
Top