Question about reading notecards
|
|
Tarl Bristol
Registered User
Join date: 12 Mar 2007
Posts: 111
|
06-19-2007 19:17
A short explaination. I am an instructor, and the class has a notecard that I read to the class over chat. I like to read 15 or 20 lines, then stop and discuss/answer questions. So I broke the main notecard into 6 or 7 parts, and made some little button objects. Each object has a short notecard and a script in it and each script is identical, except for the name of the notecard. I grabbed the bulk of the script from the library, I can't remember who wrote the bulk of it, but thanks. Added a timing function so the lines would read from the card every <gap> seconds. Works well, when I rez the buttons and leave them laying around me on the ground. What I would like is to mount the buttons on a background, the background being the root, and the buttons being children. When I do, the buttons change color when touched, but don't play the notecards. Nothing happens. Thanks in advance for your help. Any suggestions for improving the code would also be welcome. Code is below. <php> vector green=<0.0,1.0,0.0>; vector red=<1.0,0.0,0.0>; key ownerkey; key touchkey; key kQuery; integer LineCount=0; integer gap=3; string datafromcard; string cardName ="Part0"; default { on_rez(integer start) { llSetColor(green,ALL_SIDES); } touch_start(integer total_number) { ownerkey=llGetOwner(); touchkey=llDetectedKey(0); if (ownerkey != touchkey) jump done; llSetColor(red,ALL_SIDES); state readNotecard; @done; } } state readNotecard { state_entry() { kQuery=llGetNotecardLine(cardName,LineCount); } dataserver(key queryID, string data) { if (data != EOF) { datafromcard=data; llSetTimerEvent(gap); } else { state default; } } timer() { llSay(0,datafromcard); LineCount += 1; kQuery=llGetNotecardLine(cardName,LineCount); } } <php>
|
|
Qie Niangao
Coin-operated
Join date: 24 May 2006
Posts: 7,138
|
06-20-2007 03:17
Is it *desired* that once the notecard has been read, before being able to read them again you have to reset the scripts, as from Tools | Reset Scripts in Selection ? As written, the script will enter a fairly non-functional condition after reading the notecard: back in the default state but with LineCount at the EOF record, not at 0. If that's *not* the desired behavior, perhaps instead of the "state default" line, an llResetScript() would be in order, in which case I'd also change the on_rez() handler to be a state_entry() handler to set the color appropriate to the state.
A couple little things:
If each button will contain exactly one notecard, then instead of setting cardName explicitly in the declaration, you might use cardName = llGetInventoryName(INVENTORY_NOTECARD, 0); in the default state_entry, so the cards can be named anything without needing to change the scripts.
The variable "gap" is declared as an integer, but is used as the float argument to llSetTimerEvent(). Evidently the compiler is giving an implicit typecast there, but since the variable is only used as a float, it would be better if it were declared that way.
Strictly a matter of taste, but where the script has "if [...] jump done;" ... "@done" I'd have used "if [...] return;" but it's really a question of which form seems less likely to trick you when reading the code.
In this case it won't matter, but it's good to get in the habit of testing that (queryID == kQuery) in the dataserver() event. Although this script only generates one dataserver() event, if another script ever finds its way into the prim and also uses the dataserver, the scripts will get each other's events, and that queryID is how you know which ones each script should use.
|
|
Tarl Bristol
Registered User
Join date: 12 Mar 2007
Posts: 111
|
06-20-2007 06:08
Thanks Qie,
All of your suggestions are excellent. I will make the changes when I get in world later, about 8 hours from now, and let you know how it works.
|
|
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
|
06-20-2007 12:38
Personally I'd move all the functionality back into one script and use llDetectedLinkNumber to work out which button was pressed.
_____________________
I'm back......
|
|
Tarl Bristol
Registered User
Join date: 12 Mar 2007
Posts: 111
|
06-20-2007 12:54
Thanks, Newgate. I have thought about that. I want to get it working first, though. Also this method allows me to vary the <gap> times, the amount of time between lines read from the notecard. Some parts of the lecture are fairly simple, so I use a <gap> of about 5 or 6, others are more difficult, so I can slow the <gap> to 10 or 12, giving people more time to read the line. I understand that I won't be able to do that if it were all in a single script.
|
|
Qie Niangao
Coin-operated
Join date: 24 May 2006
Posts: 7,138
|
06-20-2007 16:17
Now that I think about it, maybe it would be much easier to use if there were just one notecard, with time-control and pause command lines embedded where appropriate. So the script would read in a line, check if the first character is the indicator of a command, and if so, interpret and execute the command. The buttons might just be "playback" commands (pause/play? next?) to temporarily override the timing embedded in the notecard, triggered on llDetectedLinkNumber() as Newgate suggests.
The root prim could even be populated with a selection of notecards, corresponding to different classes, with a dialog to select the one to use.
To get really fancy, the prim could llSetObjectName() to "" and llSay() each text line prefixed by "/me " to make the text appear without being labeled as coming from the object. (It would still be green, though.)
|
|
Tarl Bristol
Registered User
Join date: 12 Mar 2007
Posts: 111
|
06-20-2007 16:38
Wow Qie, those sound like great ideas, but way out my league at this point. In any case, I got it working. I think it was the llResetScript that did the trick, although I incorporated your other suggestions as well. Thanks for the help.
|
|
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
|
06-21-2007 15:54
From: Tarl Bristol Thanks, Newgate. I have thought about that. I want to get it working first, though. Also this method allows me to vary the <gap> times, the amount of time between lines read from the notecard. Some parts of the lecture are fairly simple, so I use a <gap> of about 5 or 6, others are more difficult, so I can slow the <gap> to 10 or 12, giving people more time to read the line. I understand that I won't be able to do that if it were all in a single script. You're incorrect. All you need to do is add commands within the notecard to allow you to specify the gap.
_____________________
I'm back......
|
|
Tarl Bristol
Registered User
Join date: 12 Mar 2007
Posts: 111
|
06-22-2007 06:03
Thanks Newgate. You are correct. I had forgotten that I could embed commands within the notecard itself. Thank you.
|
|
Galbraith Karami
Registered User
Join date: 12 Dec 2006
Posts: 25
|
06-22-2007 12:12
I say, why add timed gaps? If one student makes an interesting, yet unexpected question, the schedule would go off-synch. make it stop after every paragraph has been read, and start with the next at the press of the button. I see no need for timers.
|