OFPEC Forum

Editors Depot - Mission Editing and Scripting => ArmA - Editing/Scripting General => Topic started by: Deadfast on 25 Oct 2008, 11:50:13

Title: Convert string to number
Post by: Deadfast on 25 Oct 2008, 11:50:13
Hello guys,
I've been struggling to get my dialog to work.

I have a field in which you enter a value and after pressing a button the value is transferred further.


Well, the problem is it's a string and I need a number.



I've searched both this and the BI forum and found this:
http://www.ofpec.com/forum/index.php?topic=6016.0


Unfortunately it either doesn't work with SQF or I don't know how to use it properly.




Thanks for your help,
Deadfast
Title: Re: Convert string to number
Post by: Wolfrug on 25 Oct 2008, 13:21:18
Doesn't need to be that complicated in the wonderful world of ArmA anymore. Now you can simply use call compile:

Code: [Select]
_numberString = "string";
_number = call compile (_numberString);

And you should have yourself a nice little proper number. :) Good luck!

Wolfrug out.
Title: Re: Convert string to number
Post by: Deadfast on 25 Oct 2008, 13:37:00
Ah great, thank you!


I'll try it out ASAP :)
Title: Re: Convert string to number
Post by: Spooner on 25 Oct 2008, 16:03:17
Er, no. If you do it that way, you allow the player to run arbitrary scripts, which even if they are not maliciously doing it might well cause accidental damage (Not too critical in SP, but a definite no-no in MP).

You could just use the command parseNumber (http://www.ofpec.com/COMREF/index.php?action=list&game=All&letter=p#671) though, since well, that does exactly what you need! Be wary that anything that doesn't parse to a number, such as "Frogtree" will give you 0 and strings that contain numbers and non-numbers will give those numbers ("7 - fish" gives 7). Shouldn't be a problem though.
Title: Re: Convert string to number
Post by: Wolfrug on 25 Oct 2008, 21:41:13
Holy cow! Didn't even know there existed such a thing :O One learns new things every day...

Yes: use Spooner's way.

Wolfrug out.