S2i() / i2s() ?

Nevyll

New Member
Reaction score
1
I was just wondering if anybody out there knows how to convert an integer to a string or a string to an integer, hence I'm making a spell that requires the use of a hashtable, and I find it quite confusing when I simply use integers as childKeys...

Here's the spell so far:
JASS:

function Trig_Bash_Actions takes nothing returns nothing
    local unit attackedUnit = GetTriggerUnit()
    local unit attackingUnit = GetAttacker()
    local real dur = 0
    local timer t = CreateTimer()
    local integer timerID = GetHandleId( t )
    local real moveAngle = Atan2( GetUnitY( attackedUnit ) - GetUnitY( attackingUnit ), GetUnitX( attackedUnit ) -GetUnitX( attackingUnit ) )
    local real moveAmount = 2.
    local integer abilityLevel = GetUnitAbilityLevel( attackingUnit, 'A000' )
    call UnitDamageTarget( attackingUnit, attackedUnit, 25 * abilityLevel, true, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_UNKNOWN, WEAPON_TYPE_WHOKNOWS
    call SaveReal( udg_ht_AbilityTable, timerID, 0, dur )
    call SaveUnitHandle( udg_ht_AbilityTable, timerID, 1, attackedUnit )
    call SaveReal( udg_ht_AbilityTable, timerID, 2, moveAngle )
    call SaveReal( udg_ht_AbilityTable, timerID, 3, moveAmount )
    call TimerStart( t, 0.01, true, function Trig_Bash_MoveUnit )
 

Magentix

if (OP.statement == false) postCount++;
Reaction score
107
[LJASS]StringHash[/LJASS] = String to integer
[LJASS]I2S[/LJASS] = Vice versa
 

Nevyll

New Member
Reaction score
1
K, thx, but when I want to load the saved value, is
LoadReal( udg_ht_HashTable, GetHandleId( GetExpiredTimer() ), StringHash( "moveAmount" ) )
valid?
 

Darthfett

Aerospace/Cybersecurity Software Engineer
Reaction score
615
[LJASS]StringHash[/LJASS] = String to integer
[LJASS]I2S[/LJASS] = Vice versa

Actually, there is no inverse of StringHash. I2S is the inverse of S2I (and vice versa). S2I will return 0 for any string with a non-numeric character in it.

However, what Magentix meant to say, is that if you want to turn an integer into a string (I.E. for Gamecache storage), simply use I2S, and to turn a string into an integer for Hashtable storage, you simply use StringHash.

K, thx, but when I want to load the saved value, is
LoadReal( udg_ht_HashTable, GetHandleId( GetExpiredTimer() ), StringHash( "moveAmount" ) )
valid?

Yes, this is the correct way to do it.
 

Darthfett

Aerospace/Cybersecurity Software Engineer
Reaction score
615

lep

Active Member
Reaction score
8
By the fact that his function is called [ljass]Trig_Bash_Actions[/ljass], he's using a user-defined-global for the hashtable, and he's not passing structs, I took it to mean that he's not using JASSHelper/Newgen.

Following my link is a good way to start using jasshelper.
 

Magentix

if (OP.statement == false) postCount++;
Reaction score
107
[ljass]S2I(string whichString)[/ljass]?

Won't work for him, he wants to turn strings into integers for hashtables...

Well, if I was using VJass, I wouldn't have to use hashtables at all eh? :D

Actually, you would...

Since the (glorious) death of H2I, quite some systems turned to the use of hashtables...
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top