But that method you did works fine, why would you want strings for that?
tried everything but it didn't work
Trigger
Events
Player - Player 1 (Red) types a message containing -item as a Substring
Conditions
Actions
Set String = ((Entered chat string), 7, 10)
Set Unit = Your unit
Custom script: call CreateItem (S2I(udg_String), GetUnitX(udg_Unit), GetUnitY(udg_Unit))
Custom script: call UnitAddItem (udg_Unit, GetLastCreatedItem())
Custom script: call UnitAddItemById(udg_Unit, udg_String)I remember a script on WC3C that was doing this, but unfortunately, I can't find it. This trigger should work, but when I display the String variable, it returns 0. Either I can't notice what I'm doing wrong or the conversion is false.
P.S. "String" is an Integer variable.
im not sure if you make any sense xD,it cant work ....try " ' + Integer(Item code) + ' "
local integer array abilis
set abilis[0] = 'A001'
set abilis[1] = 'A002'
set abilis[2] = 'A003'
function s2i takes string s returns integer
return s
return 0
endfunction
StringHash
, which is also used to convert a string into an integer. There is also AbilityId
which I haven't been able to get working properly.Well if I remember correctly the old code that you're referring to is from pre-patch 1.24b --I believe it used a function like this for converting from a string to an integer:
JASS:function s2i takes string s returns integer return s return 0 endfunction
Since then we have lost this kind of functionality, though nobody here has mentioned anything aboutStringHash
, which is also used to convert a string into an integer. There is alsoAbilityId
which I haven't been able to get working properly.
native S2I takes string s returns integer
S2I
, it does exactly what it is supposed to do. The problem is that if you have a string "A000" and you pass it to the S2I
function, it will return 0 because "A" is not a number. The same happens for "'A000'" (notice the extra ' mark).S2I( I2S( 'A000' ) )
then it will return a string that represents the integer that is represented by 'A000'.Nothing is wrong withS2I
, it does exactly what it is supposed to do. The problem is that if you have a string "A000" and you pass it to theS2I
function, it will return 0 because "A" is not a number. The same happens for "'A000'" (notice the extra ' mark).
If you useS2I( I2S( 'A000' ) )
then it will return a string that represents the integer that is represented by 'A000'.
I believe with the old return-bug you could make it return a type-casted value, which I believe is what we are looking for here.
function String2Rawcode takes string s returns integer
local integer i = StringLength(s)
local integer j = 1
local integer k = 0
loop
exitwhen i == 0
set i = i-1
set k = k+Char2Ascii(SubString(s, i, i+1))*j
set j = j*256
endloop
return k
endfunction
function blah takes nothing returns nothing
local string test = "'hpea'"
local integer id = String2Rawcode(test)
call BJDebugMsg(I2S(id))
endfunction
if S2I(I2S('hfoo')) == 'hfoo' then
call BJDebugMsg("hello")
endif