Rai11991 Posted August 29, 2011 Share Posted August 29, 2011 I need to be able to gather an input from a string and make it into an integer. So lets say someone is told to pick and number (0-100 for an example) so they choose 5. I need to be able to take that input and make it into an integer to be used later in the script. I've been looking around for some time now. I remember doing this a while back, but can't remember the process.I'm sure I over looked something somewhere or just haven't looked enough, or this may seem like a noob request. I just want to know if it's possible to get inputs from strings and use them. Link to comment Share on other sites More sharing options...
Void Singer Posted August 29, 2011 Share Posted August 29, 2011 (integer)string_that_has_numerals_in_it Link to comment Share on other sites More sharing options...
Acheron Gloom Posted August 29, 2011 Share Posted August 29, 2011 What Void said. For more info: https://wiki.secondlife.com/wiki/Typecast Link to comment Share on other sites More sharing options...
Innula Zenovka Posted August 29, 2011 Share Posted August 29, 2011 I find this a helpful way of testing I'm getting valid input for this sort of thing: msg = (integer)llStringTrim(msg,STRING_TRIM);integer test = (integer)msg;if ((string)test == msg){//it's an integer } Link to comment Share on other sites More sharing options...
Void Singer Posted August 29, 2011 Share Posted August 29, 2011 note that integer casts will remove extra spaces when cast back to string.... so you might want to use llStringTrim if you are going to test integer data that way (also breaks on sci.notation) Link to comment Share on other sites More sharing options...
Innula Zenovka Posted August 29, 2011 Share Posted August 29, 2011 I don't understand. I've removed -- or thought that's what I was doing -- the leading and trailing spaces from msg before doing anything else. Where else do I need to remove them? ETA. I guess it's going to break with something like 123,000, though Link to comment Share on other sites More sharing options...
Void Singer Posted August 29, 2011 Share Posted August 29, 2011 whoops I was thrown by the extra integer cast on the first line and misread it... but yeah, there are several ways it can break (also on Hex and C99 float encoding), but it's good for simple stuff.... handling all cases is a pain and not worth if most of the time. Link to comment Share on other sites More sharing options...
Rai11991 Posted August 29, 2011 Author Share Posted August 29, 2011 Oh I see, thanks all. Link to comment Share on other sites More sharing options...
Recommended Posts
Please take a moment to consider if this thread is worth bumping.
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now