FOnline Development > Questions and Answers
StrToInt (and StrToFloat) - WTF
Berko:
You can also do something like that :
--- Code: ---void wtf2()
{
Log("Float : " + ("123.123".toFloat(0.0) + 542.877));
}
--- End code ---
To output "Float : 666"
But maybe you can't/don't-want-to use these string method ? (as it's a recent feature rev428)
You are working on a tool? or just doing some test? just by curiosity :p
JovankaB:
I'm writing a JSON parser in AngelScript. I didn't know string.toFloat existed, that's why I didn't use it.
Also, I want it to be back compatible with pre-rev400 (for compatibility with FOnline:2238) and that
means I can't use it at least in "2238-compatible" mode. Now that I know about it, I will most likely
make some defines for pre-rev400 and post-rev399 and use toFloat when possible.
On the other hand I store JSON Numbers as doubles not floats, so maybe I will stick to my function.
I'm not sure if it makes any difference.
The parser is mostly done but it doesn't compile with rev400 and later yet. Apparently there is a lot
of stuff that changed. I should have start testing it with the latest asscompiler a bit earlier, because
now I have tons of errors to fix.
Berko:
For information, looks like it has changed since the last revision (452, thanks Cvet)
--- Code: ---Update script compiler (ASCompiler).
When using "-run" now in addition to the function
void Log (string & text)
will work with the following functions
int Random(int min, int max)
bool StrToInt(string@+ text, int& result)
bool StrToFloat(string@+ text, float& result)
uint GetDistantion(uint16 hexX1, uint16 hexY1, uint16 hexX2, uint16 hexY2)
uint8 GetDirection(uint16 fromHexX, uint16 fromHexY, uint16 toHexX, uint16 toHexY)
uint8 GetOffsetDir(uint16 fromHexX, uint16 fromHexY, uint16 toHexX, uint16 toHexY, float offset)
uint GetTick()
uint GetAngelScriptProperty(int property)
void SetAngelScriptProperty(int property, uint value)
uint GetStrHash(string@+ str)
uint DecodeUTF8(const string& text, uint& length)
string@ EncodeUTF8(uint ucs)
--- End code ---
JovankaB:
\o/
remake:
Works at rev 412 and 2238/Reloaded upgraded to 412.
Navigation
[0] Message Index
[*] Previous page
Go to full version