Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

does listen event identify an integer? help

Mohd Belgar
Registered User
Join date: 1 Oct 2008
Posts: 14
10-01-2009 04:08
Hi guys,

I am trying to create a decimal to binary conversion in second life, but for know am trying to use the event listen to enter an input (integer) and get back an output, but thats not working, to make my self more clear consider this simple code:

-----------------

integer decimal;

default
{
state_entry()
{
llListen( 0, "", NULL_KEY, "" );
}
listen( integer channel, string name, key id, string message )
{
if ( decimal > 225 )
{
llWhisper( 0, "not acceptable" );
// open door
}
else
{
llWhisper( 0, "Hello avatar" );
// etc.
}
}
}

---------------------

know when I enter 256 am expecting the output to be (not acceptable) because the decimal I have entered is more than 255, but why am I getting (hello avatar) as an output instead?

any suggestion ?
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
10-01-2009 04:31
because you're not actually putting in a decimal. it's simply looking at decimal as it is when you compile the script, which is left blank. i assume you're saying somelike like, "decimal = 256" in chat, or you're simply saying, "256"? am i right? either way that's not enough, you need to cast the number portion of the message to an integer named decimal and then compare it, IE:

decimal = (integer)message;

CODE

integer decimal;

default
{
state_entry()
{
llListen( 0, "", NULL_KEY, "" );
}
listen( integer channel, string name, key id, string message )
{
decimal = (integer)message;
if ( decimal > 225 )
{
llWhisper( 0, "not acceptable" );
// open door
}
else
{
llWhisper( 0, "Hello avatar" );
// etc.
}
}
}
_____________________
Dark Heart Emporium

http://www.xstreetsl.com/modules.php?name=Marketplace&MerchantID=133020

want more layers for tattoos, specifically for the head? vote here
http://jira.secondlife.com/browse/VWR-1449?

llDetectedCollision* Functions similar to touch
http://jira.secondlife.com/browse/SVC-3369
Mohd Belgar
Registered User
Join date: 1 Oct 2008
Posts: 14
the simple code worked thaanx Ruthven
10-01-2009 08:54
Appreciated it worked.

But as I said my main objective is to create a decimal to binary conversion, as I tried to compile the original final code I had a problem here is the code :

--------------------------------

integer decimal;
integer b8 = 0;
integer b7 = 0;
integer b6 = 0;
integer b5 = 0;
integer b4 = 0;
integer b3 = 0;
integer b2 = 0;
integer b1 = 0;

default
{
state_entry()
{
llListen( 0, "", NULL_KEY, "" );
}
listen( integer channel, string name, key id, string message )
{
decimal = (integer)message;
if ( decimal > 225 )
{
llWhisper( 0, "This integer is not Accepted, Please Enter an Integer between 0 to 255" );

}
else

{
decimal = (integer)message;
if (decimal >= 128){
b8 = 1;
decimal = decimal - 128;

}

decimal = (integer)message;
if (decimal >= 64){
b7 = 1;
decimal = decimal - 64;

}

decimal = (integer)message;
if (decimal >= 32){
b6 = 1;
decimal = decimal - 32;

}

decimal = (integer)message;
if (decimal >= 16){
b5 = 1;
decimal = decimal - 16;

}

decimal = (integer)message;
if (decimal >= 8){
b4 = 1;
decimal = decimal - 8;

}

decimal = (integer)message;
if (decimal >= 4){
b3 = 1;
decimal = decimal - 4;

}

decimal = (integer)message;
if (decimal >= 2){
b2 = 1;
decimal = decimal - 2;
}

decimal = (integer)message;
if (decimal >= 1){
b1 = 1;
decimal = decimal - 1;
}

{
llWhisper( 0, "Binary = " + b8 = (integer)message + " " + b7 = (integer)message + " " + b6 = (integer)message + " " + b5 = (integer)message + " " + b4 = (integer)message + " " + b3 = (integer)message + " " + b2 = (integer)message + " " + b1 = (integer)message);
}

}
}
}

----------------------------

by the way the script kept compiling successfly until I have added this part:

{
llWhisper( 0, "Binary = " + b8 = (integer)message + " " + b7 = (integer)message + " " + b6 = (integer)message + " " + b5 = (integer)message + " " + b4 = (integer)message + " " + b3 = (integer)message + " " + b2 = (integer)message + " " + b1 = (integer)message);

}
---------

any suggestion ?
Meade Paravane
Hedgehog
Join date: 21 Nov 2006
Posts: 4,845
10-01-2009 09:25
From: Mohd Belgar
any suggestion ?

Maybe this totally-untested code would do it...
CODE

default
{
state_entry()
{
llListen (0, "", "", "");
}

listen (integer channel, string from, key id, string message)
{
integer i = (integer)message;
if (i == 0)
{
if (message == "0")
{
llSay (0, "0 in binary is 0");
}

return;
}

string result = "";
while (i > 0)
{
if (i & 1)
{
result += "1";
}
else
{
result += "0";
}

i /= 2;
}

llSay (0, message + " in binary is " + result);
}
}
_____________________
Tired of shouting clubs and lucky chairs? Vote for llParcelSay!!!
- Go here: http://jira.secondlife.com/browse/SVC-1224
- If you see "if you were logged in.." on the left, click it and log in
- Click the "Vote for it" link on the left
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
10-01-2009 09:28
that's because you can't use integers in a string function. you probably want to be something like

llWhisper( 0, "Binary = " +(string) b8 + " " + (string)b7 + " " + (string)b6 + " " + (string)b5 + " " + (string)b4 + " " + (string)b3 + " " + (string)b2 + " " + (string)b1);
_____________________
Dark Heart Emporium

http://www.xstreetsl.com/modules.php?name=Marketplace&MerchantID=133020

want more layers for tattoos, specifically for the head? vote here
http://jira.secondlife.com/browse/VWR-1449?

llDetectedCollision* Functions similar to touch
http://jira.secondlife.com/browse/SVC-3369
Kaluura Boa
Polygon Project
Join date: 27 Mar 2007
Posts: 194
10-01-2009 20:44
When I see such a finger-breaker line, I can't resist...

For the sake of your fingers:

llWhisper(0, llDumpList2String(["Binary =", b8, b7, b6, b5, b4, b3, b2, b1], " ";));

It does the conversion to strings and insert all the needed spaces in a very elegant way IMHO. Any way, here is a compact way to do your conversion:

default
{
state_entry()
{
llListen(0, "", NULL_KEY, "";);
}

listen(integer channel, string name, key id, string msg)
{
integer decimal = (integer)msg;
if (decimal & 0xFFFFFF00)
{
llWhisper(0, "This value is not accepted. Please enter a value in between 0 and 255";);
}
else
{
string binary;
integer i = 0;
for (; i < 8; ++i)
{
binary = (string)(decimal & 1) + binary;
decimal = decimal >> 1;
}
llWhisper(0, (string)decimal + " in binary is " + binary);
}
}
}

If you don't want the leading zeroes, just replace the 'else' block with the following:

else
{
string binary;
if (decimal)
{
while (decimal)
{
binary = (string)(decimal & 1) + binary;
decimal = decimal >> 1;
}
}
else
{
binary = "0;
}
llWhisper(0, (string)decimal + " in binary is " + binary);
}

(Quote me and you should retrieve the formating of the script.)

This is untested but I'm over-confident... :P
Madpeter Zond
Registered User
Join date: 7 Jun 2008
Posts: 7
10-03-2009 18:07
float decimal = 0.0; // this is a float not a integer
if(decimal > 255.0) // this if check now works for float values

if you where getting a user message of "255.1" it would be as text you would need
to type cast it to a float before you could check it.
listen( integer channel, string name, key id, string message )
{
float input = (float)message;
if(input > 255.0)

hope that helps ^_^
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
10-03-2009 18:24
From: Mohd Belgar
b8 = (integer)message
That means convert the entire message to an integer and assign it to b8, but you already assigned a value to b8.
_____________________
Argent Stonecutter - http://globalcausalityviolation.blogspot.com/

"And now I'm going to show you something really cool."

Skyhook Station - http://xrl.us/skyhook23
Coonspiracy Store - http://xrl.us/coonstore
Mohd Belgar
Registered User
Join date: 1 Oct 2008
Posts: 14
10-05-2009 16:36
appreciate all the help.. i'll let u know how it goes.