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

[Solved] How to add an ability based on variable/integer value?

Status
Not open for further replies.

TKF

TKF

Level 19
Joined
Nov 29, 2006
Messages
1,267
Here's the add ability function

call UnitAddAbility(GetTriggerUnit(), 'A005' )

But I want replace 'A005' with a variable of some sort, I tried several times but experience compile error everytime. I have the ability saved as a string and integer is the hashtable. What I'm doing wrong?
 
Level 7
Joined
Nov 15, 2009
Messages
225
JASS:
local integer Spell = 'A005'
call UnitAddAbility(GetTriggerUnit(), Spell)

//Some people use global blocks to replace that integer
//This looks something like this

globals
    private constant integer Spell = 'A005'
endglobals
You can use hashtables for 'Spell' either, you just need to output an integer.
 
  • Like
Reactions: TKF
Level 19
Joined
Aug 8, 2007
Messages
2,765
Here's the add ability function

call UnitAddAbility(GetTriggerUnit(), 'A005' )

But I want replace 'A005' with a variable of some sort, I tried several times but experience compile error everytime. I have the ability saved as a string and integer is the hashtable. What I'm doing wrong?

.... what?

if you want to take a string, 'A005' is an integer not a string so you have to do S2I(yourInt)

and integers cannot be hashtables without a wrapper struct
 
  • Like
Reactions: TKF
to use in a hashtable just use it as it is. 'A005' is already an integer just plug tht in as an integer. also converting it to a string would be a lot less efficient since u would have to convert to integer when u use it. so keep it as integer

ex:
JASS:
call SaveInteger( hashtable, parentkey, childkey, 'A005')

how to use:
JASS:
call UnitAddAbility( unit, LoadInteger( hash, parentkey, childkey)

this way is faster than hashtables tho
JASS:
local integer Spell = 'A005'
call UnitAddAbility(GetTriggerUnit(), Spell)

//Some people use global blocks to replace that integer
//This looks something like this

globals
    private constant integer Spell = 'A005'
endglobals
You can use hashtables for 'Spell' either, you just need to output an integer.

edit: 'A005' is ASCII in case u didnt know this
 
  • Like
Reactions: TKF
Status
Not open for further replies.
Top