Home   Help Search Login Register  

Author Topic: Convert string to number  (Read 1933 times)

0 Members and 1 Guest are viewing this topic.

Offline Deadfast

  • Members
  • *
Convert string to number
« 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

Offline Wolfrug

  • Addons Depot
  • Former Staff
  • ****
  • Official OFPEC Old Timer
Re: Convert string to number
« Reply #1 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.
"When 900 years YOU reach, look as good you will not!"

Offline Deadfast

  • Members
  • *
Re: Convert string to number
« Reply #2 on: 25 Oct 2008, 13:37:00 »
Ah great, thank you!


I'll try it out ASAP :)

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: Convert string to number
« Reply #3 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 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.
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline Wolfrug

  • Addons Depot
  • Former Staff
  • ****
  • Official OFPEC Old Timer
Re: Convert string to number
« Reply #4 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.
"When 900 years YOU reach, look as good you will not!"