OFPEC Forum
Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: snYpir on 04 Feb 2003, 09:12:33
-
This may have been answered before (and yes i have searched!)...
Is there a quick way to change the type of a variable? In particular, change a string to a number?
I have a dialog, and in it there are edit fields. Now, these edit fields are strings by default. To change the strings to a number i am using a function as follows (also attached):
// a very limited way to convert a positive string to a number
// is there a better way to do this?
private ["_string","_c"];
_string = _this;
_c = -1;
while { (format["%1",_c]) != _string } do
{
_c = _c + 1
};
_c
It simply increments a counter until it equals the string. VERY limited, because:
- It doesn't work for floats (only integers)
- It only works up to numbers smaller than 10000 (because it is a function)
- It is slow and a stupid way to do this
Anyone able to suggest a better method (and tell me if there is a simple way to do this, pehaps a command i missed or something?) :P
-
Upon seeing this topic I recalled something in my snippets file (the text file of pieces of stolen code I have collected over the years)...
It went something like this:
Call "MyFloat = "+MyString
I mucked around with it, as I'm not quite smart enough to understand it and came up with this:
Call format ["Variable = "+ string ]
Which will make Variable the number version of your string. It works with floats (as far as I could tell), and you can rename (or retype is more accurate I think) an existing variable using that code.
As I said, I stole this off some smart guy (can't remember who I'm afraid) so full credit to them, rather than to me ;)
-
Fantastic! I'll give it a go... ;D
-
Works like a charm. I have made it a function, and added it to the function library. What other gems do you have in that file? ;)
-
Most of it is pretty basic stuff from back in the day...
Some of it is useful but random, like the class name for bullet cartridge is "FXCartridge" ;)
Basically when I see something I didn't know, I copy it and paste it in there...