Integer to String conversion wanted.
|
Allen Harrington
Registered User
Join date: 14 Jul 2005
Posts: 60
|
03-25-2007 10:30
I know this is discussed some where but the forum's search engine sucks. I see Typecast mentioned in topics related to converting lists to integers and vectors to stings. The script wiki has no heading that relates to translating one type of variable to another. I tried searching it and could not fine anything like a integer to string function.
Would someone show me an example of how to display an integer value in a "llSay" or "llSetText" line of code?
Thank you
Allen
_____________________
Photo Gallery at www.tigerzero.com Anthrocon 2004 & 2005 photos at www.tigerzero.com
|
2fast4u Nabob
SL-ice.net
Join date: 28 Dec 2005
Posts: 542
|
03-25-2007 10:44
Try this
default {
state_entry() { integer myNumber = 5;
llSay(0, "Hello..the number is...." + (string)myNumber); }
}
The output is: Hello..the number is....5 The thing in brackets - (string) - is what performs the typecast. -2fast
|
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
|
03-25-2007 11:25
I would suggest you take the time to read the sticky's at the top of the forum. They give references to several tutorials on the basic's of the language.
|
Cryas Tokhes
Great Googley Moogley...
Join date: 8 Feb 2006
Posts: 124
|
03-25-2007 15:28
Also probably just seeing it and using it, it might be helpful to become more familiar with the what that (string) actually does. http://www.lslwiki.net/lslwiki/wakka.php?wakka=TypecastThis feature is known as typecasting.. Becomes very helpful if used properly. You can do more with it then what was just posted here. 
|
Fenrir Reitveld
Crazy? Don't mind if I do
Join date: 20 Apr 2005
Posts: 459
|
03-26-2007 11:04
And if you want to display just the whole part of a float variable: float mydata = 1.25 ; list split = llParseString2List ((string)mydata, ["."], []) ; llSay (0, "Whole = " + llList2String (split, 0)) ; llSay (0, "Remainder = " + llList2String (split, 1)) ;
Conversely, you could typecast it from a float to an integer, and even use the llCeil/llFloor functions if you want to trim it a certain way. eq: integer mydatainteger = (integer)(llCeil (mydata)) ;
_____________________
---- ---- ----
|
Eloise Pasteur
Curious Individual
Join date: 14 Jul 2004
Posts: 1,952
|
03-26-2007 15:32
Or, if you're phobic about lists and want to do the integer and mantissa part of a float: llOwnerSay("The integer part is "+llGetSubString((string)number, 0, llGetSubStringIndex((string)number, ".")); and llOwnerSay("The mantissa is "+llGetSubString((string)number, llGetSubStringIndex((string)number, "."), -1);
|
Allen Harrington
Registered User
Join date: 14 Jul 2005
Posts: 60
|
03-26-2007 15:34
Thank you all for your assistance. I knew it had to be a simple thing. I never would have thought the only place thay would have information on how to typecast whould be the tutorials. You would think it would have been explainded in the LSL wiki's variable page.
_____________________
Photo Gallery at www.tigerzero.com Anthrocon 2004 & 2005 photos at www.tigerzero.com
|
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
|
03-26-2007 15:51
From: Allen Harrington Thank you all for your assistance. I knew it had to be a simple thing. I never would have thought the only place thay would have information on how to typecast whould be the tutorials. You would think it would have been explainded in the LSL wiki's variable page. Its actually covered under the string page
|
Cryas Tokhes
Great Googley Moogley...
Join date: 8 Feb 2006
Posts: 124
|
03-26-2007 21:25
From: Allen Harrington Thank you all for your assistance. I knew it had to be a simple thing. I never would have thought the only place thay would have information on how to typecast whould be the tutorials. You would think it would have been explainded in the LSL wiki's variable page. yeah, the only thing was that they made a link that noted 'typecast'. but that is a single sentence in the variables wiki page. I have noticed with the wiki, it is a good idea to read EVERYTHING on the page.. Just scanning tends to cause additional confusion since it is a good chance to miss something important.
|
Osgeld Barmy
Registered User
Join date: 22 Mar 2005
Posts: 3,336
|
03-26-2007 22:28
if for some reason you knew what it was called its also in the page index http://lslwiki.net/lslwiki/wakka.php?wakka=Typecastbut i know its impossible to scan tru the index without knowing what your looking for
|
Allen Harrington
Registered User
Join date: 14 Jul 2005
Posts: 60
|
03-30-2007 07:30
I didn't notice there was a Page Index in the old wiki. I guess my mistake was using the "LSL Portal" to find it. The search function on the "LSL Portal" yeilded lot's of information which used the word "typecast". I didn't think the try"typecasting", but that too doesn't seem to help much. The way I see it. If you can't find what you are looking for after 30 minutes of looking, it's time to ask someone. It doesn't hurt to ask even if you may feel stupid after finding out how simple the answer was.
_____________________
Photo Gallery at www.tigerzero.com Anthrocon 2004 & 2005 photos at www.tigerzero.com
|
2fast4u Nabob
SL-ice.net
Join date: 28 Dec 2005
Posts: 542
|
03-30-2007 11:07
From: Allen Harrington It doesn't hurt to ask even.... Typecasting is a concept that is familiar to people that already have a background in using languages like C, C++ and others. So, don't worry about asking questions like that if you don't have a lot of programming experience. I found it odd that LL decided to require typecasts for a scripting language. While typecasts certainly make the developer's intent clear, it adds little value to a scripting language since, by definition, scripting languages work at a much higher level than languages like Java, C++, or C# and often perform implicit typecasts on behalf of the developer at runtime. Of course, the argument could be that typecasting improves performance because the runtime does not have to infer what conversion is necessary; however, performance is not (and cannot be) a key feature of a scripting language anyway. I've gone off-topic, but don't be afraid to ask if - as you said - you have already done your research.  -2fast
|
Allen Harrington
Registered User
Join date: 14 Jul 2005
Posts: 60
|
03-30-2007 13:11
Just a Quick note. I have only had 1 quarter class of C++. Most of my programming experiance has been with the "Fourth" programming language.
_____________________
Photo Gallery at www.tigerzero.com Anthrocon 2004 & 2005 photos at www.tigerzero.com
|
Peekay Semyorka
Registered User
Join date: 18 Nov 2006
Posts: 337
|
03-30-2007 15:43
Forth you mean? I love tooling around with embedded microcontrollers (68HC, PIC, etc.), but for some reason never learned Forth... mostly C or just assembly.
-peekay
|