Hud Buttons
|
Rez Shepherd
Registered User
Join date: 16 Jul 2008
Posts: 4
|
01-24-2010 16:42
Greetings, I am hoping someone can lend a hand with a HUD that I have created for use in classes that I teach in SL. It is basically is a texture slide show. I load my lecture points into the object, the students wear it, and they can click anywhere on the HUD to advance it to the next texture. However, it would be great if I could add "Back" and "Next" buttons to the HUD, so students could return to an earlier slide without having to cycle through the entire series. I was reading about the llDetectedLinkNumber and llDetectedTouchFace functions, but I am just a beginning scripter, and I am afraid it's a bit over my head. Here's the code for the HUD that I have. Can anyone make suggestions on what to add to include prim buttons? // options integer face = 4; float thickness = 0.01;
// globals integer current_image; string Texture_card;
//script default { state_entry() { Texture_card = llGetInventoryName(INVENTORY_NOTECARD,0); llOwnerSay("ready"); }
touch_start(integer t) { integer x; for (x = 0;x < t;x += 1) { if (llDetectedKey(x) == llGetOwner()) { llGetNotecardLine(Texture_card,current_image); } else { llWhisper(0, "You're not the owner of this board, " +llDetectedName(x)); } } }
//not checking your dataserver reqest key is unwise... //in complex dataserver events
dataserver(key na, string input) { if (input != EOF && input != " ") { list output = llParseString2List(input,["|"],[]); llSetTexture(llList2String(output,0),face); llSetScale( < thickness, (float)llList2String(output,1), (float)llList2String(output,2)> ); ++current_image; output = []; }
else { current_image = 0; llGetNotecardLine(Texture_card,current_image); } } }
|
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
|
01-24-2010 17:05
Link a prim to the one containing this script. That's your BACK button. Then in the touch_start event, add this just before llGetNotecardLine ......... if (llDetectedLinkNumber(0) == 2) { --current_image; }
That should do it, I think. ETA: BTW, the embedded comment about the wisdom of checking your request ID is a good one. You really should say reqID = llGetNotecardLine (blah blah blah) and then wrap the statements in the dataserver event with a test that says if(na == reqID){ //Do stuff}. Oh, and make reqID global.
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask....  Look for my work in XStreetSL at 
|
Rez Shepherd
Registered User
Join date: 16 Jul 2008
Posts: 4
|
01-24-2010 17:36
From: Rolig Loon Link a prim to the one containing this script. That's your BACK button. Then in the touch_start event, add this just before llGetNotecardLine ......... if (llDetectedLinkNumber(0) == 2) { --current_image; }
That should do it, I think. ETA: BTW, the embedded comment about the wisdom of checking your request ID is a good one. You really should say reqID = llGetNotecardLine (blah blah blah) and then wrap the statements in the dataserver event with a test that says if(na == reqID){ //Do stuff}. Oh, and make reqID global. Like this? touch_start(integer t) { integer x; for (x = 0;x < t;x += 1) { if (llDetectedKey(x) == llGetOwner()) { if (llDetectedLinkNumber(0) == 2) { --current_image; } llGetNotecardLine(Texture_card,current_image); } else { llWhisper(0, "You're not the owner of this board, " +llDetectedName(x)); } } I am guessing that isn't the right place, since it doesn't want to move back. I will toy with it some more. Thanks!
|
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
|
01-24-2010 18:24
From: Rez Shepherd Like this?
touch_start(integer t) { integer x;
for (x = 0;x < t;x += 1) { if (llDetectedKey(x) == llGetOwner()) { if (llDetectedLinkNumber(0) == 2) { --current_image; } llGetNotecardLine(Texture_card,current_image); } else { llWhisper(0, "You're not the owner of this board, " +llDetectedName(x)); } }
I am guessing that isn't the right place, since it doesn't want to move back.
I will toy with it some more.
Thanks! That's the right place, and it should work.. Basically, all you want to do is back up one line from the current one and read the line before it. If it's not working, check a few things..... First, be sure that the BACK button prim is the child in the linkset, not the root. It's the one that's highlighted in blue when you're in Edit mode. You can also test temporarily by putting the line llOwnerSay("Yes, you really did click the BACK button."  ; inside that if test. If it doesn't speak to you, you'll know where your problem is. It's also worth checking to see that you're not already at line 0 (the first line) on the card. If you are, and you try to back up, you'll be asking for line -1, and the call will fail silently. You may want to write a little failsafe against that possibility. Otherwise, if you've checked those those things and it STILL doesn't work, we'll try again. ETA: BTW, if you want to dissect a slide show with forward and reverse buttons that DOES work, visit the Virtual Learning Library on Info Island at http://slurl.com/secondlife/Info%20Island/61/243/40. There's one there you can grab, free.
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask....  Look for my work in XStreetSL at 
|
Johan Laurasia
Fully Rezzed
Join date: 31 Oct 2006
Posts: 1,394
|
01-24-2010 18:31
There's a more efficient way, link two buttons to the hud, name them, and this code will return which button was pushed.
integer hudchan = 0; // for testing purposes
default { touch_start(integer num) { llSay(hudchan, llGetLinkName(llDetectedLinkNumber(0))); } }
_____________________
My tutes http://www.youtube.com/johanlaurasia
|
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
|
01-24-2010 18:38
Yes, that's true. Names are easier to remember and harder to mess up if you link and unlink prims. In a one-button device, though, you can pretty much do with link numbers. Besides, that's not truly the challenge here. The challenge is to get the button to work. THEN you can name it if you want. 
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask....  Look for my work in XStreetSL at 
|
Rez Shepherd
Registered User
Join date: 16 Jul 2008
Posts: 4
|
01-24-2010 19:12
Okay, it does work, but it only works once. After that the button doesn't respond. I tried resetting the script and trying again, and it did the same thing. It works once.
I picked up the other script, too. I am looking at that one now.
|
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
|
01-24-2010 19:29
Ah... I see why too. There's a line in your dataserver event that automatically advances to the next image ( ++current_image). That means that if you click the BACK button a second time, you aren;t starting from where you left off, but starting from where you were before you touched the BACK button. One step backwards, one step forwards, again and again. SO, the way to beat that is to put the advance command in the touch_start event instead. Try this .... touch_start(integer t) { integer x;
for (x = 0;x < t;x += 1) { if (llDetectedKey(x) == llGetOwner()) { if (llDetectedLinkNumber(0) == 2) { --current_image; } else if (llDetectedLinkNumber(0) ==1) { ++current_image; } llGetNotecardLine(Texture_card,current_image); } else { llWhisper(0, "You're not the owner of this board, " +llDetectedName(x)); } } }
Remove the ++current_image line from the dataserver event (or comment it out) and just to be sure that you always start with the first image, put current_image = -1; in the state_entry event. I think that will do it. /me has her fingers crossed. 
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask....  Look for my work in XStreetSL at 
|
Rez Shepherd
Registered User
Join date: 16 Jul 2008
Posts: 4
|
01-24-2010 19:58
Yes, that did it!
Thanks so much!
|
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
|
01-24-2010 20:20
I do love it when a plan works. BTW, as you fiddle and make this a prettier and prettier device, one thing you'll want to do (other than take Johan's advice about naming the button prim  ) is to figure a way to reset the thing when you get to the end of the show. Right now it just stops. You can always reset the whole script, or you can figure a way to loop through the images. That other device you picked up offers one way to do it that you might borrow. Good luck.
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask....  Look for my work in XStreetSL at 
|