• Check out the results of the Techtree Contest #19!
  • 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.
  • Create a void inspired texture for Warcraft 3 and enter Hive's 34th Texturing Contest: Void! Click here to enter!
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!

UnitAddAbility does not recognize integer variable

Status
Not open for further replies.

Ardenian

A

Ardenian

To reduce the functions in my map, I merged some triggers and wrote a general
one.
I have a problem with adding abilities saved in a variable.

JASS:
// In map conf:

set udg_ChaosAbility[1] = 'h000' 
// udg_ChaosAbility is an integer variable with array

// in trigger

call UnitAddAbility( udg_TempUnit, udg_ChaosAbility[1])

However, it does not work, the unit is not transformed.
( ChaosAbility is a Chaos-based ability)

Interesting though, as this works:

JASS:
local integer abilityid = udg_ChaosAbility[1] 
// when the variable is an ability variable with array

call UnitAddAbility( udg_TempUnit, abilityid)

Could you please enlighten me ?
 
In this case I know 100% sure the lines I posted are causing this.

It seems making udg_Chaos_Ability[array] an ability variable and simply placing it in
UnitAddAbility works.
Though I don't understand why setting an integer variable to the ability only works when
setting a local integer to the integer variable and the placing the local integer instead of
the integer variable in UnitAddAbility
 
Hm, strange, very strange. I said with believe that the lines are sufficient as the problem
solves itself when setting a local integer to the global integer variable and using the local in
the UnitAddAbility().
There isn't really code I can post without pages of explanations why I do this and that.
However, here is a small example:

JASS:
local unit u = CreateUnit( Player(0), 'hfoo', x, y, facing)
        call UnitAddAbility( u, 'Aloc')
        call UnitRemoveAbility( u, 'Aloc')
        call UnitAddAbility( u, udg_DG_Chaos_Ability[whichability])
        set u = null

// array whichability is an integer the function takes
 
Are you modifying udg_ChaosAbility anywhere else? Try moving this line:
set udg_ChaosAbility[1] = 'h000'

Immediately before UnitAddAbility. I'm guessing that you are calling another event (through your code) that will modify udg_ChaosAbility, so it ends up adding the wrong ability.

This post explains what I'm referring to. If you launch any events inbetween the assignment of udg_ChaosAbility to 'h001' and UnitAddAbility, and that event ends up changing udg_ChaosAbility within its actions, then it can cause a conflict. That would explain why the local variable assignment works when the global variable doesn't.
 
I set udg_ChaosAbility[1] in the map initialization, after that it is not set to anything else.
Hm, however, I would not exclude the possibility that the issue you desribe occurs,
might be a wrong line somewhere.

Alright, thank you PurgeandFire and Dr Super Good!
 
Status
Not open for further replies.
Back
Top