• 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.

Vector of 1's

Status
Not open for further replies.
Level 21
Joined
May 16, 2012
Messages
644
How do you know it doesn't work? It should. Maybe you're reading the value to early, before InitGlobals() is called.


I'm not reading it to early, the trigger that uses it only runs when a unit deals spell damage, so its after game starts.

JASS:
scope SpellPower initializer Init

private function Conditions takes nothing returns boolean
    return udg_PDD_damageType == udg_PDD_SPELL
endfunction

private function Actions takes nothing returns nothing
    set udg_PDD_amount = (udg_PDD_amount + udg_SpellPowerFlat[GetUnitUserData(udg_PDD_source)]) * udg_SpellPowerPercent[GetUnitUserData(udg_PDD_source)]
endfunction

//===========================================================================
private function Init takes nothing returns nothing
    set gg_trg_SpellPower = CreateTrigger()
    call TriggerRegisterVariableEvent(gg_trg_SpellPower, "udg_PDD_damageEventTrigger", EQUAL, 1.00)
    call TriggerAddCondition(gg_trg_SpellPower, Condition( function Conditions ))
    call TriggerAddAction(gg_trg_SpellPower, function Actions)
endfunction

endscope

udg_SpellPowerPercent is the vector variable that i want to be initialized with 1's. When a unit deals spell damage, the amount becomes zero, and the only way for it to happen is if its being multiplied by 0.
 
Level 13
Joined
May 10, 2009
Messages
868
What's the array size defined in the variable editor? Keep in mind that the initial value will only affect the indices from 0 up to "size field".

upload_2019-1-25_22-12-17.png

->
JASS:
function InitGlobals takes nothing returns nothing
    local integer i= 0
    set i=0
    loop
        exitwhen ( i > 5 )
        set udg_RealArray[i]=5.00
        set i=i + 1
    endloop

endfunction
 
Level 21
Joined
May 16, 2012
Messages
644
What's the array size defined in the variable editor? Keep in mind that the initial value will only affect the indices from 0 up to "size field".

View attachment 314636
->
JASS:
function InitGlobals takes nothing returns nothing
    local integer i= 0
    set i=0
    loop
        exitwhen ( i > 5 )
        set udg_RealArray[i]=5.00
        set i=i + 1
    endloop

endfunction

Oh i didn't know that, the initial size is by default 1, so only the 0 and 1 indexes are actually 1. I want it to be dynamic, because i don't know yet how many units will be able to cast spells in my map, but i guess i can use a array of size 1000 or so. Thx for the help anyway, that will solve the problem.
 
Level 13
Joined
May 10, 2009
Messages
868
hm... Since your units are already making use of Custom Value, then assign the value of 1 to the corresponding index of udg_SpellPowerPercent after giving a unique id to them (I'm assuming you are using custom values for that matter).

EDIT: Does udg_SpellPowerPercent vary for each unit depending on certain circumstances, or it's just the same value all the time for all of them?
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,285
As you expand the array you can initialize it.

In worst case you could even have an accompanying boolean array to mark which indices have been initialized. But this seems kind of wasteful...

If you are using a unit indexing system then in response to a unit being indexed by the system you can initialize the indices of the array to appropriate values. Some indexing systems have a GUI friendly event system that operates by monitoring the value of a variable for changes with the specific changes corresponding to specific system events.
 
Level 21
Joined
May 16, 2012
Messages
644
if you're using Bribe's Unit Event, solution is simple: when unit enters the map, set its variable to 1.00: (UDex is a unit's custom value)
  • Untitled Trigger 001
    • Events
      • Game - UnitIndexEvent becomes Equal to 1.00
    • Conditions
    • Actions
      • Set YourRealVariable[UDex] = 1.00

i am, and its probably the best solution. I could also just add one to the vector value when running my trigger, but i think this is better
 
Status
Not open for further replies.
Top