• 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] Get an ability (integer) from a string

Status
Not open for further replies.
Level 2
Joined
Dec 16, 2012
Messages
10
Hello, everyone.
I want a buff to display a number in order to show how many charges an ability has remaining.
I tried to do so by using an Slow Tornado ability with green colors for the buff display, but the main problem was that aura's buffs take a few seconds to update when leveled up, so I was thinking in creating multiple abilities with the same two first letters for the integer part and the last two for the level (SK01, SK02, SK03, SK04...).
I created a string and an integer variables to make my idea work, but I got stuck in the process as I'm not too skilled in JASS.
Which functions should I use for what I want to do?

Thanks in advance.
 
Last edited by a moderator:
Level 20
Joined
Jul 14, 2011
Messages
3,213
You can use this library to turn any string into an ability (or any) id integer. Just do:

call String2Id("Abil") and it will return 'Abil' as an integer.
Note: You must not add the quotes to the Abil Id. Just the numbers and characters.

JASS:
// Credits to AceHart for this.
library Char2IdLib

    // No need to touch this. Credits to AceHart for this.
    function Char2Id takes string c returns integer
        local integer i = 0
        local string abc = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
        local string t

        loop
            set t = SubString(abc,i,i + 1)
            exitwhen t == null or t == c
            set i = i + 1
        endloop
        if i < 10 then
            return i + 48
        elseif i < 36 then
            return i + 55
        endif
        return i + 61
    endfunction

    // No need to touch this. Credits to AceHart for this.
    function String2Id takes string s returns integer
        return ((Char2Id(SubString(s,0,1)) * 256 + Char2Id(SubString(s,1,2))) * 256 + Char2Id(SubString(s,2,3))) * 256 + Char2Id(SubString(s,3,4))
    endfunction
endlibrary
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
Name your spells 'Buff Level 1', 'Buff Level 2', ... 'Buff level 10' ... 'Buff level 100', ect.

use constant native AbilityId takes string abilityIdString returns integer?

pass in "Buff level "+I2S(LevelOfAbility) for the string (notice the space in the first string).

you missed one thing in common.j tho:
JASS:
// Not currently working correctly...
constant native AbilityId                   takes string  abilityIdString   returns integer
constant native AbilityId2String            takes integer abilityId         returns string

those functions are not working yet and never will most likely
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
well, StringHash works but that would output some shit numbers

I suggest something like Mr. Bean said, make you can then just check if unit has this buff, and if it has set some integer to the rawcode of buff - raw code of 1 level buff - 1 (so you get 1 for 1 lvl, 2 for 2 lvl ...)
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
I2S works only when the string contains numbers alone. String "1234" returns Int = 1234
String " '1234' " returns 0. String "A000" returns 0. Since all abilities have a non numeric character, the functions is nearly useless, unless it's used for Input Chat String like "-Transfer 1000"
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
@dimf:
Did you see the Thread Title?: "Get an ability (integer) from a string".

@Say41Plz
What do you want to achieve? I don't really get why you need the strings and integers stuff. What thing did you do with the arrays to make your Strings and Integers work together?

Seems like Mr Bean suggestion is the most suitable.
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
Well... the librare I published successfully turns characters into their respective decimal value based on the ASCII table
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
I don't know exactly what you mean... sorry, my native language is Spanish.

Well, the system just reads the 4 digits of an Id ( "asdf") and turns them to the respective value of 'asdf'
 
Level 2
Joined
Dec 16, 2012
Messages
10
Just checked the thread, sorry for not answering earlier.
Mr. Bean's suggestion seems to be the best idea so far; I figured it out earlier, but I thought there was some other way to do it without using more variables.
Btw, I knew abilties were variable values (looked it in the JASS api browser), but didn't know AbilityId function does not work properly (I tried using that function before asking for help) as well as some other mentioned; that's Blizzard for you, I guess xD.

Thanks to you all for your help!
 
Status
Not open for further replies.
Top