Jump to content

List to Integer Not Working As Expected


Selphie Wirefly
 Share

You are about to reply to a thread that has been inactive for 1272 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

I've striped this down to basically the bare bones of my issue  The resulting integer, next_x, is used elsewhere in the complete script, the llSay aspect just exists for troubleshooting.

The expected action here, when touched, the Prim will say the same number (picked from x_range) twice.

Instead what happens is the first llSay (string)next_x, always says 0, while the second, with the llList2String, works as expected.

I'm not sure what I'm doing wrong here and it feels like a simple issue.

list x_range = [-.5, 0, .5, 0];
integer counter;
 
default
{
    touch_start(integer total_number)
    {
    integer next_x=(integer)llList2String(x_range,counter);
    llSay(0,(string)next_x);
    llSay(0,llList2String(x_range,counter));
    counter++;
    }
}

 

Link to comment
Share on other sites

sometimes using llList2String and then casting it the wanted type can be useful

like integer n = (integer)llList2String(x_range, 0)

we often need to do this when a list is filled from a notecard, as notecard lines are read/retrieved as strings

Link to comment
Share on other sites

Technically, the (integer)llList2String is kind of working. (By that I mean it could be considered "correct" depending on what you want.)

The values returned by List2String are something like "0.00000" and "0.50000" and then you cast them to integers, which throws out the ".00000" part and you're left with the whole number 0. You can see what I mean if you try a value like 1.5 or 253.0.

But yeah, if you want fractional values, you need llList2Float or just llList2String without anything extra.

  • Like 1
Link to comment
Share on other sites

12 hours ago, Wulfie Reanimator said:

Technically, the (integer)llList2String is kind of working. (By that I mean it could be considered "correct" depending on what you want.)

The values returned by List2String are something like "0.00000" and "0.50000" and then you cast them to integers, which throws out the ".00000" part and you're left with the whole number 0. You can see what I mean if you try a value like 1.5 or 253.0.

But yeah, if you want fractional values, you need llList2Float or just llList2String without anything extra.

 

You know in hind site, casting a .5 to int really was an obvious problem. 

In the larger script, I am using the list to control regular movement positions.  The adjustments being made will loop through the list and move a prim around as needed along one axis on a timer.

Link to comment
Share on other sites

adding to the conversation

when we want regular partitioning (of the result of some calculation that can be irregular) then llRound() is useful

example rounding to tenths


float f = 2.152
f = llRound(f * 10.0) / 10.0
f * 10.0 = 21.52
llRound(f) = 22
22 / 10.0 = 2.2


float f = 2.148
f = llRound(f * 10.0) / 10.0;
f * 10.0 = 21.48
llRound(f) = 21
21 / 10.0 = 2.1

Edited by Mollymews
  • Like 1
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 1272 days.

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
 Share

×
×
  • Create New...