|
Jin Takakura
Registered User
Join date: 27 Apr 2006
Posts: 11
|
05-21-2006 19:38
Hi, I'm pretty new to scripting with LSL. I'm designing a script for a class instructor that will scan the area for people (the students) that keeps scanning until the instructor tells it to stop (by saying a command). Then after that, the script will prompt the instructor for his name, then the name of the class. There's more to the project, but that's the part I'm currently working on. Here's what I've coded so far: string name; string classname; integer i = 0; integer z = 0; list mylist;
default { on_rez(integer start_param) { llWhisper(0, "Type /11 end class to end scanning. Please allow a few seconds afterward."); llListen(11,"",NULL_KEY,""); llSensorRepeat("","",AGENT,96,PI,3); } sensor(integer n){ integer count = 0; integer j; integer a; integer listsize; string nameAt; listsize = llGetListLength(mylist); for (j = 0; j<n; j++) { for ( a = 0; a<listsize; a++) { nameAt = llList2String(mylist, a); if (nameAt == llDetectedName(j)) { count++; } } if (count == 0) { mylist += llDetectedName(j)+"\n"; } } } listen(integer a, string name, key id, string msg) { integer listsize; integer b; string out; string listcount; if (msg == "end class"){ if ( z == 0) { listsize = llGetListLength(mylist)/2; listcount = (string)listsize; llWhisper(0,"there's "+listcount+" people"); for (b = 0; b<listsize; b++) { out = llList2String(mylist,b); llWhisper(0,out); } //z++; } } llSay(0,"Instructor's name? "); llListen(11,"",NULL_KEY,""); if (z == 1) { name = msg; llSay(0,"Instructor's name: "+name); } z++; } }
I'm having problems after I tell the script to end scan (by saying '/11 end class') and prompting the instructor to enter name, then enter class name (both stored in separate string variables). Any help or hints please? I'd really appreciate it, thanks!
|
|
Draco18s Majestic
Registered User
Join date: 19 Sep 2005
Posts: 2,744
|
05-21-2006 20:10
In your listen event, where it says "if(msg == "end class"  " you don't, as far as I can tell, end the class. You have this instead. if ( z == 0) { listsize = llGetListLength(mylist)/2; listcount = (string)listsize; llWhisper(0,"there's "+listcount+" people"); for (b = 0; b<listsize; b++) { out = llList2String(mylist,b); llWhisper(0,out); } //z++; }
And I'm not entirely sure what it is supposed to do. And the part you have to get the instructor's name, llSay(0,"Instructor's name? "); llListen(11,"",NULL_KEY,""); if (z == 1) { name = msg; llSay(0,"Instructor's name: "+name); } z++;
Should be placed in a different event. If the instructor comes by first, you might as well put it in a touch event. Instructor comes along and touches the object and supplies info. It shouldn't happen every time he says something to the object.
|
|
Jin Takakura
Registered User
Join date: 27 Apr 2006
Posts: 11
|
05-21-2006 21:13
oh sorry I should've clarified. When I say "end class" it doesn't actually 'end the class', it's just being said, hehe sorry it's confusing....I just want it to read out all the people in the area for now.
And about the touch event, thanks I should consider that!
What about getting the name of the class though?
Thanks for the advice!
|
|
Draco18s Majestic
Registered User
Join date: 19 Sep 2005
Posts: 2,744
|
05-21-2006 21:19
in the touch event, send it to a new state and have a listen event to listen for the class name and stuff...maybe make the instructor say, "/11 Class Name: <name>" and "/11 Instructor Name: <name>" and you can filter for the right information, erm....need to find the lines of code... string parse(string message) { list raw = llParseString2List(message, [":"], []); integer rawLen = llGetListLength(raw); string command = llList2String(raw, 1); return command; }
That should return "Class Name" and "Instructor Name" respectively. You can then use the same code, but string command = llList2String(raw, 2); to get the names.
|
|
Jin Takakura
Registered User
Join date: 27 Apr 2006
Posts: 11
|
05-21-2006 21:34
ok thanks a lot i will try that. Who thought I/O would be so confusing, heh.
|
|
Draco18s Majestic
Registered User
Join date: 19 Sep 2005
Posts: 2,744
|
05-21-2006 21:55
I/O in an event based lanuage is tricky, especially "random" input (that is, input that can't be expected, such as a name). Good thing we have States to take care of that.
|