1. Find your way through the deepest dungeon in the 18th Mini Mapping Contest Poll.
    Dismiss Notice
  2. A brave new world lies beyond the seven seas. Join the 34th Modeling Contest today!
    Dismiss Notice
  3. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
Hive 3 Remoosed BETA - NOW LIVE. Go check it out at BETA Hive Workshop! Post your feedback in this new forum BETA Feedback.
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

[Solved] Get an ability (integer) from a string

Discussion in 'World Editor Help Zone' started by Say41Plz, Jul 14, 2013.

  1. Say41Plz

    Say41Plz

    Joined:
    Dec 16, 2012
    Messages:
    10
    Resources:
    0
    Resources:
    0
    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: Jul 17, 2013
  2. Mr_Bean

    Mr_Bean

    Joined:
    Feb 11, 2011
    Messages:
    1,823
    Resources:
    6
    Maps:
    2
    Spells:
    4
    Resources:
    6
    How many abilities are there? If there aren't too many, you don't need to do anything fancy, you can just create an integer array and set each element manually. Such as:

    Code (vJASS):
    set abilities[0] = 'SK01'
    set abilities[1] = 'SK02'
    set abilities[2] = 'SK03'
    ...
     
  3. Chaosy

    Chaosy

    Tutorial Reviewer

    Joined:
    Jun 9, 2011
    Messages:
    11,102
    Resources:
    18
    Icons:
    1
    Maps:
    1
    Spells:
    10
    Tutorials:
    6
    Resources:
    18
    I would do something like
    Code (vJASS):

    local integer i = GetTriggerAbilityId() //written on phone so cant check this syntax error
    if i == 1234 then
    elseif i == 5678 then
    elseif i == 9876 then
    endif
    //I lack knowledge on or conditions so cant do better
     
     
  4. Zeatherann

    Zeatherann

    Joined:
    Nov 25, 2008
    Messages:
    1,303
    Resources:
    6
    Skins:
    1
    Tools:
    1
    Maps:
    4
    Resources:
    6
    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).
     
  5. Spartipilo

    Spartipilo

    Joined:
    Jul 14, 2011
    Messages:
    3,190
    Resources:
    0
    Resources:
    0
    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.

    Code (vJASS):

    // 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
     
     
  6. deathismyfriend

    deathismyfriend

    Joined:
    Oct 24, 2012
    Messages:
    6,526
    Resources:
    14
    Spells:
    12
    Tutorials:
    2
    Resources:
    14
    u should use Mr. Beans method. if there are a lot of abilities then use a hashtable keyed to the ability id.

    note that ability ids are ASCII values which r integers not strings. So im not sure what u want done w the strings.
     
  7. edo494

    edo494

    Joined:
    Apr 16, 2012
    Messages:
    3,846
    Resources:
    5
    Spells:
    1
    JASS:
    4
    Resources:
    5
    you missed one thing in common.j tho:
    Code (vJASS):

    // 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
     
  8. Spartipilo

    Spartipilo

    Joined:
    Jul 14, 2011
    Messages:
    3,190
    Resources:
    0
    Resources:
    0
    Neither I2S, or StringHash, nor AbilityId2String works.
     
  9. edo494

    edo494

    Joined:
    Apr 16, 2012
    Messages:
    3,846
    Resources:
    5
    Spells:
    1
    JASS:
    4
    Resources:
    5
    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 ...)
     
  10. Zeatherann

    Zeatherann

    Joined:
    Nov 25, 2008
    Messages:
    1,303
    Resources:
    6
    Skins:
    1
    Tools:
    1
    Maps:
    4
    Resources:
    6
    If I2S didn't work, then many many things would fail.
     
  11. Spartipilo

    Spartipilo

    Joined:
    Jul 14, 2011
    Messages:
    3,190
    Resources:
    0
    Resources:
    0
    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"
     
  12. deathismyfriend

    deathismyfriend

    Joined:
    Oct 24, 2012
    Messages:
    6,526
    Resources:
    14
    Spells:
    12
    Tutorials:
    2
    Resources:
    14
    @spartipilo
    i still have no idea y u r trying to use strings since all ability ids are integers not strings ? what is the point of doing it this way ?
     
  13. Spartipilo

    Spartipilo

    Joined:
    Jul 14, 2011
    Messages:
    3,190
    Resources:
    0
    Resources:
    0
    @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.
     
  14. deathismyfriend

    deathismyfriend

    Joined:
    Oct 24, 2012
    Messages:
    6,526
    Resources:
    14
    Spells:
    12
    Tutorials:
    2
    Resources:
    14
    ya i saw it but im guessing that he doesnt know that ability ids are integers.
     
  15. Spartipilo

    Spartipilo

    Joined:
    Jul 14, 2011
    Messages:
    3,190
    Resources:
    0
    Resources:
    0
    I'm guessing he does ^^ hehehe
     
  16. deathismyfriend

    deathismyfriend

    Joined:
    Oct 24, 2012
    Messages:
    6,526
    Resources:
    14
    Spells:
    12
    Tutorials:
    2
    Resources:
    14
    mybe we will have to wait and see.
     
  17. Zeatherann

    Zeatherann

    Joined:
    Nov 25, 2008
    Messages:
    1,303
    Resources:
    6
    Skins:
    1
    Tools:
    1
    Maps:
    4
    Resources:
    6
    Btw: no language has a convert integer to string function that works with non-numerical characters.
     
  18. Spartipilo

    Spartipilo

    Joined:
    Jul 14, 2011
    Messages:
    3,190
    Resources:
    0
    Resources:
    0
    Well... the librare I published successfully turns characters into their respective decimal value based on the ASCII table
     
  19. Zeatherann

    Zeatherann

    Joined:
    Nov 25, 2008
    Messages:
    1,303
    Resources:
    6
    Skins:
    1
    Tools:
    1
    Maps:
    4
    Resources:
    6
    But that isn't a lexical cast now is it?
     
  20. Spartipilo

    Spartipilo

    Joined:
    Jul 14, 2011
    Messages:
    3,190
    Resources:
    0
    Resources:
    0
    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'