Jump to content

"if" function is saying that 1 is greater than 2


Diogetz Barbosa
 Share

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

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

Recommended Posts

Hello, IM really confused right now because my script is saying that 1 is greater than 2... This never happened before

i will put parts of the code to try to explain:

integer ab = (integer)x.x - (integer)postarget.x;  //the result of this is 1
llSay(0,(string)ab); // just to confirm the result, it says: 1
if(ab > 2)
{

llSay(0, "Error");
}

and than it says "Error", dont know why.

if it is my mistake let me know. thanks

Link to comment
Share on other sites

Hmm.  This behaves as expected (i.e., says "1" but doesn't say "error", which makes me wonder what's happening in your code.

default{    state_entry()    {       integer ab =1;       llOwnerSay((string)ab);       if(ab>2){           llOwnerSay("error");        }    }}

 Can there be a typo in your original code, where you are evaluating the condition, that's not been reproduced here -- that is, you've typed here what you think you've typed in the script, not what's actually there (which I frequently do -- find my script doesn't say what I'm sure I typed).

Link to comment
Share on other sites

in the original script the x.x and the postarget.x that result on the ab are sent from a sensor in other place, but i already tested if it is correct, but what is bottering me is that the llSay, is saying ab as 1, what proves that it is one : /

dont know if this haves something to do with it, but in the original code there is another if after this one

this one is really the original one this time :)

 

integer ab = (integer)x.x - (integer)postarget.x;
llSay(0,(string)ab); // it says: 1

if(ab >= 2)
{
if(nx != targetname)    //nx is really different from targetname.
{

nx = "error";
}}

if(ab < 2)
{
if(nx != targetname) //nx is really different from targetname.
{

nx = "clear";
}}

llSay(0,nx);

ab is = 1 , and it says error

Link to comment
Share on other sites

But if you replace the line 

 integer ab = (integer)x.x - (integer)postarget.x;  

 with 

 integer ab = 1; 

 it works perfectly.   So it's something about the definition of integer ab that's causing the problem, or so it seems to me.

ETA -- this works fine, too!

default{    state_entry()    {        string nx ="a";        string targetname="a";        //integer ab = (integer)x.x - (integer)postarget.x;        integer ab  = (integer)1.73;        llSay(0,(string)ab); // it says: 1        if(ab >= 2)        {            if(nx != targetname)    //nx is really different from targetname.            {                nx = "error";            }        }        if(ab < 2)        {            if(nx != targetname) //nx is really different from targetname.            {                nx = "clear";            }        }        llSay(0,nx);    }}

 What are nx and targetname?  

Link to comment
Share on other sites

depends on how/where you declare variable nx

pencil test shows 4 conditions (edit: of your code as written)

at start

nx = undefined (possibly "error" ??)

conditions:

1) if (ab >= 2) and (nx != targetname) then nx = "error"

2) if (ab >= 2) and (nx == targetname) then nx = undefined

3) if (ab < 2)  and (nx != targetname) then nx = "clear"

4) if (ab < 2)  and (nx == targetname) then nx = undefined

 

on condition 1) say nx = "error"

on condition 3) say nx = "clear"

on conditions 2) 4) say nx = undefined

 

is condition 4) that can seemingly? give you (1 >= 2 and nx = "error") when

nx = "error" defined at start

or on previous execution condition 1) was true and nx was undefined at start

 

+

eep cant even work out my own logic until I edit about 5 times lol (:

Link to comment
Share on other sites

  • 1 month later...

Integers and floats are stored differently. Most program languages will cast the integer to a float before checking, but it seems this didn't. Floats are stored as a group of bits organized based on the sign, the exponent, and the mantissa (what is being raised). This means 1.0 could very well be greaer than 2, if compared as bits rather than the value. Integers are merely stored based on a predictable base 2 system, which we know as biinary. When you have to break it into pieces to get a float, the language has to compensate for that. LSL should've caught that.

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 4097 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...