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

Saving Ability ID (from String)

Status
Not open for further replies.
Level 16
Joined
Mar 27, 2011
Messages
1,349
Hi,

I'm trying to save some ability IDs into a hashtable as an integer. See below:

JASS:
call SaveInteger(pokeMoveId, pokemonHandle, index, S2I(subStringResult))
call BJDebugMsg("subStringResult = " + subStringResult)
call BJDebugMsg("move = " + I2S(LoadInteger(pokeMoveId, pokemonHandle, index)))
call BJDebugMsg("move should be - " + I2S('A007'))

subStringResult (a string) contains a valid number 'A007' though the second BJDebugMsg contains 0
The move's numerical format should be 1093677111

It seems I can't convert from an ability ID ('A007') in a string to an integer. Any idea how I can do this? If this can't be done, is there a function which I can use to convert from 'A007' to numerical form without running the game and copying it down during gameplay?

Side note, what do I call a number expressed in letters like A007? Is this "Hexadecimal" to identify an ability ID?

As a workaround, I could potentially use a special calculator to give me the numerical number so I don't use 'A007' numbers in my system.
 
Last edited:
A string "A007" is not the same as the number 'A007'. With the single quote, 'A007' is a normal integer, just not in decimal representation, but in base 256. As consequence, a normal string "A007" won't ever be a valid integer, and the result of an attempt of converting it will become 0, just the default integer value.

There are snippets which calculate the correst integer number out of a string, which would be exactly what you ask for. Example:
.. with using first one for example it would look like local integer abilityId = S2A("A007") .. the integer will have the value of 'A007'.

For doing the reverse thing, said libraries can also help you, going back from 'A007' to "A007", but blizzard also made their own function for it in the cheats.j file.
Look forfunction DebugIdInteger2IdString takes integer value returns string.
 
Level 16
Joined
Mar 27, 2011
Messages
1,349
A string "A007" is not the same as the number 'A007'. With the single quote, 'A007' is a normal integer, just not in decimal representation, but in base 256. As consequence, a normal string "A007" won't ever be a valid integer, and the result of an attempt of converting it will become 0, just the default integer value.

There are snippets which calculate the correst integer number out of a string, which would be exactly what you ask for. Example:
.. with using first one for example it would look like local integer abilityId = S2A("A007") .. the integer will have the value of 'A007'.

For doing the reverse thing, said libraries can also help you, going back from 'A007' to "A007", but blizzard also made their own function for it in the cheats.j file.
Look forfunction DebugIdInteger2IdString takes integer value returns string.


Thanks, I'll look into implementing these. Though I can't find a good tutorial anywhere explaining what base 256 is nor can I find any online calculator to convert a base 256 number (such as A007) to decimal. Lots of mention of base 5, 6, 7, 8 etc on the internet. This is going way over my head...

I'm confused how you have a situation in which you are being given an ability id as a string formatted as '####'. Can you share how/where/why you're getting them that way? Where does SubStringResult come from?

I am making a Pokemon game and decided to store each Pokemon's moveset into a hashtable. With each pokemon having about 12 moves, I realized I would need 12 lines of code for each Pokemon. To make things easier, I decided to store all info into a string then have a function interpret this string into the respective hashtables.


JASS:
    call InitPokeMoves(pokemonHandle, ",1,'A007',3,'A008',6,'A009',>")

    private static method InitPokeMoves takes integer pokemonHandle, string moveSet returns nothing
     
        local integer index = 0
        local string subString = "a" // Junk value to begin with
        local string subStringResult
        local integer subStringStart = -1
        local integer subStringEnd = -1
        local integer stringPosition = 0
        local integer tempInt
        local boolean readingLevel = true
        local boolean skipIncrement = false

        call BJDebugMsg("InitPokeMoves executed")
        //call BJDebugMsg("moveSet = " + moveSet)
        //call BJDebugMsg("pokemonHandle = " + I2S(pokemonHandle))


        loop         
            set subString = SubString(moveSet, stringPosition, stringPosition + 1)
            exitwhen subString == ">"

            if subString == "," then
                if subStringStart == -1 then
                    set subStringStart = stringPosition + 1
                else
                    set subStringEnd = stringPosition - 1
                endif
            endif

            if subStringEnd != -1 then
                set subStringResult = SubString(moveSet, subStringStart, subStringEnd + 1)
                call BJDebugMsg("index = " + I2S(index))

                if readingLevel == true then
                    call SaveInteger(pokeMoveLevel, pokemonHandle, index, S2I(subStringResult))
                    set readingLevel = false
                    //call BJDebugMsg("level = " + subStringResult)
                else
                    set tempInt = S2I(subStringResult)
                    call SaveInteger(pokeMoveId, pokemonHandle, index, tempInt)
                    set readingLevel = true
                    set index = index + 1
                    call BJDebugMsg("subStringResult = " + subStringResult)
                    call BJDebugMsg("move = " + I2S(LoadInteger(pokeMoveId, pokemonHandle, index)))
                    call BJDebugMsg("move should be - " + I2S('A007'))

                    set tempInt = GetSpellAbilityId('A007')

                endif

                set subStringStart = -1
                set subStringEnd = -1
                set skipIncrement = true

            endif
            if skipIncrement == true then
                set skipIncrement = false
            else
                set stringPosition = stringPosition + 1
            endif
         
        endloop

        //call BJDebugMsg("InitPokeMoves finished execution")
 
        set subString = null
        set subStringResult = null

    endmethod


Unfortunately this doesn't work because I can't save base 256 numbers to decimals when they are stored within a string. I'll look into IcemanBo's link to see if I can convert the numbers
 
Last edited:
You can look up in the internet how to convert numbers between bases, the shema is basically always the same. Also when going to base10, the decimal that we want.

ValueInBase * BASE^Order = value of a symbol in decimal

When converting 'A007' to decimal it would look like:

'A'*256^3 + '0'*256^2 + '0'*256^1 + '7'*256^0

.. be aware that there are still the single quotes, for example in '0'. We need to look at the ascii table, to find the decimal value of the symbols in base 256.
From table we see 'A' has the decimal value 65.. '0' is 48.. and '7' is 55.

So the formula in our decimal standard looks like

65*256^3 + 48*256^2 + 48*256^1 + 55*256^0

.. you can print this in wc3 (outwritten)

65*(256*256*256) + 48*(256*256) + 48*(256) + 55

and then print I2S('A007'), it'll be the same.
 

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,190
I am making a Pokemon game and decided to store each Pokemon's moveset into a hashtable. With each pokemon having about 12 moves, I realized I would need 12 lines of code for each Pokemon. To make things easier, I decided to store all info into a string then have a function interpret this string into the respective hashtables.
Generally it is better to have the 12 lines of code. One can make it neater by separating each record with comments and avoiding hard coding record numbers.
 
Level 16
Joined
Mar 27, 2011
Messages
1,349
Generally it is better to have the 12 lines of code. One can make it neater by separating each record with comments and avoiding hard coding record numbers.

Fair call. That would mean my efforts are for naut, lol. Though I suppose using the 12 lines would improve performance. A lot less function calls.

Thanks for you help everyone.


Edit: Oh and I forgot. I need to save 2 values. so 12 moves means 24 lines of code :/
 
Last edited:
Status
Not open for further replies.
Top