Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

inputing

Nathan Klein
FataleKlein Island Owner
Join date: 18 Sep 2004
Posts: 38
01-21-2005 03:00
hi all I need some help here... how do I input a number into my script

ie
From: someone

Nathan Klein > dist 50
Object > My distance is now 50 meters.
Nathan Klein > done
Object > setup closed.


I look all around wiki and could find anything, any help would be great thanks in advance.

NK
_____________________
...Waiting for Linux Client...
See My Final Fantasy XI Character here.

Adam Zaius
Deus
Join date: 9 Jan 2004
Posts: 1,483
01-21-2005 03:07
From: Nathan Klein
hi all I need some help here... how do I input a number into my script

ie


I look all around wiki and could find anything, any help would be great thanks in advance.

NK


llListen is the function you need. There should be examples of how to use it in the 'examples' section of the wiki. :)

-Adam
_____________________
Co-Founder / Lead Developer
GigasSecondServer
Tcoz Bach
Tyrell Victim
Join date: 10 Dec 2002
Posts: 973
01-21-2005 10:08
integer iListen0;
// this will be a reference to your listener.
// You do not need the reference, but it's a good idea to get used to using them.
// if you wish to remove the listener, which is a sim friendly practice,
// you would say llListenRemove(iListen0);

integer iChannel = 0;
// channel you want to listen on, 0 is regular chat
// you may listen on, and submit commands on, non visual channels
// by using the form "/channelnumber command" (without the quotes)
// i.e., /7 50 would say "50" on channel 7, and nobody would see it.

default
{
state_entry()
{
iListen0 = llListen(iChannel, "", llGetOwner(), "";);
// iListen0 is now a reference to this specific listener
}

listen(integer chnl, string s, key id, string m)
{
llSay(0, "I am at " + m + " meters";);
// m is the incoming message.
// if the owner of the object says "50", the obect will say, "I am at 50 meters"

llListenRemove(iListen0);
// the object will now stop listening until the script is reset
// or until you create a new listener.
// leave this out if you want the object to keep on listening.
}
}
_____________________
** ...you want to do WHAT with that cube? **
Nathan Klein
FataleKlein Island Owner
Join date: 18 Sep 2004
Posts: 38
01-21-2005 11:41
okay and when my script calls up the dist it will still remember the number? ie it was set to 50
_____________________
...Waiting for Linux Client...
See My Final Fantasy XI Character here.

Tcoz Bach
Tyrell Victim
Join date: 10 Dec 2002
Posts: 973
01-21-2005 11:54
No you would have to set the info to a variable for that. So...

integer iListen0;
// this will be a reference to your listener.
// You do not need the reference, but it's a good idea to get used to using them.
// if you wish to remove the listener, which is a sim friendly practice,
// you would say llListenRemove(iListen0);

integer iChannel = 0;
// channel you want to listen on, 0 is regular chat
// you may listen on, and submit commands on, non visual channels
// by using the form "/channelnumber command" (without the quotes)
// i.e., /7 50 would say "50" on channel 7, and nobody would see it.

integer iKeepNumber;
// this variable will be used to store your incoming number
// so that your program remembers it and can use it
// anywhere in the script.

default
{
state_entry()
{
iListen0 = llListen(iChannel, "", llGetOwner(), "";);
// iListen0 is now a reference to this specific listener
}

listen(integer chnl, string s, key id, string m)
{
iKeepNumber = (integer)m
// this turns the incoming text message into a number
// and stores it in the iKeepNumber variable.
// until you clear the variable or the script crashes.

llSay(0, "I am at " + m + " meters";);
// m is the incoming message.
// if the owner of the object says "50", the obect will say, "I am at 50 meters"

llListenRemove(iListen0);
// the object will now stop listening until the script is reset
// or until you create a new listener.
// leave this out if you want the object to keep on listening.
}
}

This is a VERY basic example, and overlooks some best practices for the sake of simplicity. For instance, you would want to know something about floats vs. integers, casting (i.e. changing "strings", that is, text, into numbers, or numbers into strings) and how to validate an incoming command to ensure it is indeed a number.

For instance, you can not llSay(0, "I am at " + iKeepNumber + " meters";), because llSay does not know how to "say" a number, it only knows how to say strings. You would have to "cast" (change) into a string, like this...

llSay(0, "I am at " + (string)iKeepNumber + " meters";);

Keep in mind this does not change the original variable, it only interprets it into a string for this use. iKeepNumber is still an integer.

To keep the code short, you can remove all lines that start with "//". Those are comments and have nothing to do with the running code.

If you want more help look me up in game I actually hate posting code on the forums. However, if you can get this working, the Wiki might make more sense.

Good luck.
_____________________
** ...you want to do WHAT with that cube? **
Nathan Klein
FataleKlein Island Owner
Join date: 18 Sep 2004
Posts: 38
01-21-2005 21:41
thanks so much ^_^
_____________________
...Waiting for Linux Client...
See My Final Fantasy XI Character here.