Difference between revisions of "ListToWholeNumbers"

From Second Life Wiki
Jump to navigation Jump to search
m
Line 1: Line 1:
{{LSL Header}} __NOTOC__
{{LSL_Function
<div id="box">
|mode=user
== Function: [[list]] ListToWholeNumbers([[list]] {{LSL Param|mylist}}); ==
|func=ListToWholeNumbers
<div style="padding: 0.5em;">
|p1_type=list|p1_name=mylist
Removes one item from a list.
|return_type=list
 
|return_text=that contains the elements of '''myList''' but with the float elements having their fractional parts removed.
|func_desc=Takes a list and truncates each float in the list so that it is a whole number.
|func_footnote=
See also: [[List|Lists]]
See also: [[List|Lists]]
 
|examples=
<lsl>
<lsl>list myWholeNumberList = ListToWholeNumbers( [1.04, 10.789, 4.643] );//yields [1,10,4]</lsl>
list ListToWholeNumbers(list myList) {
|spec=<lsl>list ListToWholeNumbers(list myList)
    list myConvertedList = [];
{
     integer ListLength = llGetListLength(myList);
     integer ListLength = llGetListLength(myList);
     integer f = 0;
     integer i = -1;
     while (f <= (ListLength - 1)) {
     while (++i < ListLength)
        string w =llList2Key(myList, f);
    {
        integer y = (integer)w;
        if(TYPE_FLOAT == llGetListEntryType(myList, i))
        myConvertedList = (myConvertedList=[]) + myConvertedList + y;
        {
        f=f+1;
            float f = llList2Float(myList, i);
            if(llFabs(f) < 0x1000000)//can it have an fpart?
                f = (integer)f;
            myList = (myList = []) + llListReplaceList(myList, (list)f, i, i);
         }
         }
     return myConvertedList;
    }
}
     return myList;
 
}</lsl>
</lsl>
|helpers
 
|also_functions
list myWholeNumberList = ListToWholeNumbers(1.04,10.789,4.643);<br />
|also_events
//yields [1,10,4]
|also_tests
 
|also_articles
 
|location
</div>
|notes
 
|cat1=Examples
{{LSLC|Examples|ListToWholeNumbers}}
|cat2
|cat3
|cat4
}}

Revision as of 20:05, 14 July 2008

Summary

Function: list ListToWholeNumbers( list mylist );

Takes a list and truncates each float in the list so that it is a whole number.
Returns a list that contains the elements of myList but with the float elements having their fractional parts removed.

• list mylist

See also: Lists

Specification

<lsl>list ListToWholeNumbers(list myList) {

   integer ListLength = llGetListLength(myList);
   integer i = -1;
   while (++i < ListLength)
   {
       if(TYPE_FLOAT == llGetListEntryType(myList, i))
       {
           float f = llList2Float(myList, i);
           if(llFabs(f) < 0x1000000)//can it have an fpart?
               f = (integer)f;
           myList = (myList = []) + llListReplaceList(myList, (list)f, i, i);
       }
   }
   return myList;

}</lsl>

Examples

<lsl>list myWholeNumberList = ListToWholeNumbers( [1.04, 10.789, 4.643] );//yields [1,10,4]</lsl>