Any of you clever people...

...have any idea of how to convert a string to an integer?

I am trying to use the set_property() and get_property() functions to help me automate my protesting.

But in order to do that correctly, I need the results of get_property() to be an integer.

From what I can determine, there is no string_to_int() function, nor is there anyway to break up a string.

For instance, if we could take one character at a time from a string (preferably starting from the right), I could write a script to turn a string into an integer.

So... Anyone have any great ideas?
 

Veracity

Developer
Staff member
Interesting.

I can envision wanting to store any (simple) data type as the value of a property. Integers, booleans, whatever.

ASH currently provides xxx_to_string functions for every type.
It should provide string_to_xxx functions that can reliably do the inverse transformation, but throw a RuntimeException if you give it a bogus string.

I'll look into it, by and by.
 
Ah. Thanks for the interest Veracity.

For now, I have figured out a workaround.

I'll post it in the writing in progress board when I have had a chance to run it and make sure it sort of functions.

For those interested, I figured if I can not break a string up into individual characters, I should save it in individual characters.
 

Veracity

Developer
Staff member
I just submitted some new functions to ASH.

string boolean_to_string( boolean );
boolean string_to_boolean( string );

string int_to_string( int );
int string_to_int( string );

string float_to_string( float );
float string_to_float( string );

string item_to_string( item );
item string_to_item( string );

string zodiac_to_string( zodiac );
zodiac string_to_zodiac( string );

string location_to_string( location );
location string_to_location( string );

string class_to_string( class );
class string_to_class( string );

string stat_to_string( stat );
stat string_to_stat( string );

string skill_to_string( skill );
skill string_to_skill( string );

string effect_to_string( effect );
effect string_to_effect( string );

string familiar_to_string( familiar );
familiar string_to_familiar( string );

string slot_to_string( slot );
slot string_to_slot( string );

string monster_to_string( monster );
monster string_to_monster( string );

The "_to_string" functions are not new.
However, I list each of them next to its inverse, which is new.

The "string_to_xxx" function is guaranteed to be able to parse without error the string generated by "xxx_to_string". You can give "string_to_xxx" something bogus, and you will get an IllegalArgumentException.

Here's a little test script:

Code:
boolean var1 = true;
int var2 = 10;
float var3 = 3.1415926535;
item var4 = $item[seal tooth];
zodiac var5 = $zodiac[marmot];
location var6 = $location[Degrassi Knoll];
class var7 = $class[Sauceror];
stat var8 = $stat[Muscle];
skill var9 = $skill[Pastamastery];
effect var10 = $effect[Beaten Up];
familiar var11 = $familiar[mosquito];
slot var12 = $slot[weapon];
monster var13 = $monster[Vampire Bat];

print( var1 + " " + ( string_to_boolean( boolean_to_string( var1 ) ) == var1 ) );
print( var2 + " " + ( string_to_int( int_to_string( var2 ) ) == var2 ) );
print( var3 + " " + ( string_to_float( float_to_string( var3 ) ) == var3 ) );
print( var4 + " " + ( string_to_item( item_to_string( var4 ) ) == var4 ) );
print( var5 + " " + ( string_to_zodiac( zodiac_to_string( var5 ) ) == var5 ) );
print( var6 + " " + ( string_to_location( location_to_string( var6 ) ) == var6 ) );
print( var7 + " " + ( string_to_class( class_to_string( var7 ) ) == var7 ) );
print( var8 + " " + ( string_to_stat( stat_to_string( var8 ) ) == var8 ) );
print( var9 + " " + ( string_to_skill( skill_to_string( var9 ) ) == var9 ) );
print( var10 + " " + ( string_to_effect( effect_to_string( var10 ) ) == var10 ) );
print( var11 + " " + ( string_to_familiar( familiar_to_string( var11 ) ) == var11 ) );
print( var12 + " " + ( string_to_slot( slot_to_string( var12 ) ) == var12 ) );
print( var13 + " " + ( string_to_monster( monster_to_string( var13 ) ) == var13 ) );

and here is the output when I execute it:

> coerce.ash
true true
10 true
3.1415926535 true
seal tooth true
Marmot true
Degrassi Knoll true
Sauceror true
Muscle true
Pastamastery true
Beaten Up true
Mosquito true
weapon true
Vampire Bat true
Script succeeded!
 
Well...

I got my script to work. And I will be putting it up in the Outdated forum, since as soon as this goes live - it will be outdated. :p
 
Top