Possible to show/hide floating text on touch?
|
|
Cheewha Palen
Registered User
Join date: 27 Nov 2007
Posts: 78
|
07-22-2008 17:12
Hi
I have some scripts that use float text to display info (avatar radar, sim info, etc) and I do not always want to look at the text. I see from wiki that llSetText has opt to alpha out text. I am trying to figure out how to set this up in a touch event.
I imagine this would be done with a if/then or if/else statement. I am having trouble imagining how to switch the alpha state for floating text on and off by touch.
Can anyone please provide a generic example of float text turned on/off by a touch so I can see how its structured?
Thank you!
|
|
Osgeld Barmy
Registered User
Join date: 22 Mar 2005
Posts: 3,336
|
07-22-2008 17:30
without using states //script start integer switch = 0;
default { touch_start(integer t) { if (switch == 0) { llSetText("some text", <1,1,1>, 1); switch = 1; } else if (switch == 1) { llSetText("",<1,1,1>,1); switch = 0; } } } // end script
not tested but the basic idea, no real need to fiddle with the alpha, since you have to use 2 calls just blip out the text
|
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
07-22-2008 17:39
Well, unfortunately you can't set just the alpha value of the text without also setting the text string, so you have to remember the text or always reset it. Here is a way you could do it: (Note: Syntax problems fixed.) string textStr = ""; vector textColor = <1.0, 1.0, 1.0>; float textAlpha = 1.0; integer textVisible = TRUE;
setFloatText(string text, vector color, float alpha) { textStr = text; textColor = color; textAlpha = alpha; if (textStr != "" && textAlpha > 0.0 && textVisible) { llSetText(textStr, textColor, textAlpha); } else { llSetText("", ZERO_VECTOR, 0.0); } }
setFloatTextVisible(integer visible) { if (visible == textVisible) { return; } textVisible = visible;
if (textStr != "" && textAlpha > 0.0 && textVisible) { llSetText(textStr, textColor, textAlpha); } else { llSetText("", ZERO_VECTOR, 0.0); } }
toggleFloatTextVisibility() { setFloatTextVisible(!textVisible); }
default { state_entry() { // Use setFloatText() instead of llSetText() }
touch_start(integer nDetected) { toggleFloatTextVisibility(); }
// ... }
|
|
Cheewha Palen
Registered User
Join date: 27 Nov 2007
Posts: 78
|
07-22-2008 18:04
Wow Thank you for the quick responses! I will post my progress and let you guys know how I did.
|
|
Ron Khondji
Entirely unlike.
Join date: 6 Jan 2007
Posts: 224
|
07-22-2008 23:47
If you only want to change the alpha value you could do something like this: From: someone string text = "Hello avatar!"; vector color = <1,1,1>; float alpha; integer touched;
default { touch_start(integer total_number) { if (touched){ alpha = 0.0; touched = FALSE; } else { alpha = 1.0; touched = TRUE; } llSetText(text,color,alpha); } }
|
|
Tyken Hightower
Automagical
Join date: 15 Feb 2006
Posts: 472
|
07-23-2008 08:26
From: Hewee Zetkin Well, unfortunately you can't set just the alpha value of the text without also setting the text string, so you have to remember the text or always reset it. Here is a way you could do it:
...
While the intentions and structure of this are all well and good, do you really need 3 functions to toggle llSetText? The guy isn't sure how to use a touch_start event to toggle, so maybe this is a bit much.. 
|
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
07-23-2008 10:10
From: Tyken Hightower While the intentions and structure of this are all well and good, do you really need 3 functions to toggle llSetText? The guy isn't sure how to use a touch_start event to toggle, so maybe this is a bit much..  Eh. It should make the rest of the code dirt simple: replace all uses of llSetText() with setFloatText(), used in exactly the same manner. The OP seemed to know how to use llSetText() for a simple case, so that seemed pretty safe. Usability before performance. 
|
|
Cheewha Palen
Registered User
Join date: 27 Nov 2007
Posts: 78
|
07-23-2008 13:48
Sorry Hewee I still haven't figured it out. LSL is my first coding to learn so maybe I am missing the obvious. I am struggling with getting the pieces to fit together. I understand the basic concept of LSL //state{ event(augument) and functions// and I can look at something like //llSetText("", <1.0, 1.0, 1.0>, 1.0);// and decipher its components but at this point syntax still seems to be an issue for me. Please be patient I am trying hard to understand and learn. Also I can look at your example and see what it is you are spelling out but again I may be missing the obvious. The main issue I am receiving (other than syntax error) is "not defined within scope" which I understand to mean that variables called are not named within an event. I think that is what is troubling me and hope that may help. Thank you again for everyones help it is much appreciated! This is the script I am trying to toggle. default { on_rez(integer x) { llResetScript(); } state_entry() { llSetTimerEvent(1); }
timer() { string rn = llGetRegionName(); string lo = llKey2Name(llGetLandOwnerAt(llGetPos()));
if (lo == "") { lo = "Group Owned"; } float di = llGetRegionTimeDilation(); integer fs = (integer) llGetRegionFPS(); vector la = llGetPos();
llSetText("Region: " + rn + " \n Land Owner: " + lo + "\n Dilation: " + (string) di + " \n FPS: " + (string) fs + "\n Position: " + (string) la,<0,1,1>,1); } }
|
|
Qie Niangao
Coin-operated
Join date: 24 May 2006
Posts: 7,138
|
07-23-2008 18:54
Because the timer fires every second, one is tempted to cheat and just wait for that timer to expire to reflect the hide-or-show effect of a touch. But in case that timer gets longer (as it probably should), maybe something like: integer showText = TRUE; string regionText;
floatText() { string textToShow = ""; if (showText) textToShow = regionText; llSetText(textToShow, <0,1,1>, (float)showText); //0.0 alpha if showText is FALSE }
default { on_rez(integer x) { llResetScript(); } state_entry() { llSetTimerEvent(1); } touch_start(integer num_detected) { showText = ! showText; // Toggle show/hide floatText(); } timer() { string rn = llGetRegionName(); string lo = llKey2Name(llGetLandOwnerAt(llGetPos())); if (lo == "") { lo = "Group Owned"; } float di = llGetRegionTimeDilation(); integer fs = (integer) llGetRegionFPS(); vector la = llGetPos(); regionText = "Region: " + rn + " \n Land Owner: " + lo + "\n Dilation: " + (string) di + " \n FPS: " + (string) fs + "\n Position: " + (string) la; floatText(); } }
_____________________
Archived for Your Protection
|
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
07-23-2008 21:14
From: Cheewha Palen Sorry Hewee I still haven't figured it out. LSL is my first coding to learn so maybe I am missing the obvious.
I am struggling with getting the pieces to fit together. I understand the basic concept of LSL //state{ event(augument) and functions// and I can look at something like //llSetText("", <1.0, 1.0, 1.0>, 1.0);// and decipher its components but at this point syntax still seems to be an issue for me. Please be patient I am trying hard to understand and learn. Also I can look at your example and see what it is you are spelling out but again I may be missing the obvious. No problem at all. All you have to do is place those variables and functions (everything before 'default') at the top of your own script. Then, instead of calling--for example: llSetText("hello", <1.0, 1.0, 1.0>, 1.0) just call the function I wrote with the same parameters: setFloatText("hello", <1.0, 1.0, 1.0>, 1.0) Then you can use the 'touch_start' handler I put in there, or you can yourself call setFloatTextVisible(TRUE) if you want it to be visible and setFloatTextVisible(FALSE) if you want it to disappear. Or call toggleFloatTextVisibility() if you want it to appear/disappear when it is invisible/visible. (Again, you don't have to do anything other than switch from llSetText() to setFloatText() if you keep the 'touch_start' handler I wrote). I fixed the code above (edit) , so now it shouldn't generate any compile errors.
|
|
Osgeld Barmy
Registered User
Join date: 22 Mar 2005
Posts: 3,336
|
07-23-2008 21:38
wow, i even started to get loopy from reading that
Hewee, i have nothing but respect for ya ...
|
|
Cheewha Palen
Registered User
Join date: 27 Nov 2007
Posts: 78
|
07-23-2008 23:03
Thank you so extremely much everyone!
I was surprised this hasnt been addressed before a way to toggle float text? I can see this application at malls with maybe a sensor to detect an avatars presence and then toggle on the text and toggle off again when no one around. Not sure though if running a sensor would defeat the purpose of toggling off the text for performance...LOL.
Anyhow again thanks I did learn from all of you and I think I chose a tricky script to want to modify. It provides valuable information but is annoying and ugly when not needed.
And yes after reading Hewee's 1000's of posts I am in utter awe! You are a machine my friend!
Smiles be well!
*EDIT*
Awesome! I just added the code to another script which is similar (an avatar scanner) and works flawlessly!
Thanks again everyone!
|