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

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 ?
 

Ardenian

A

Ardenian

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
 

Ardenian

A

Ardenian

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.
 

Ardenian

A

Ardenian

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