Jump to content

Script to display info after touch


trondheimtour
 Share

You are about to reply to a thread that has been inactive for 3372 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

Hi,

 

I need to write a script  for the following function.

I have a human character in SL . I want to display a floating text above that character .

Then if  the avatar touch the charater , then it should display some kind of information .The information is a detialed one so that it can long for upto a paragraph ...

 

How can i do this . Hope i can get a ready made script , I am in a hurry to make it done in few days. :(

Link to comment
Share on other sites


trondheimtour wrote:

I need to write a script  for the following function.

Hope i can get a ready made script

You won't get a ready-made script here (at least not from me), this is the LSL Scripting forum and is used to educate and inform people who are learning - or want to learn - LSL. If you are willing to pay for a script to be written for you, you should post your requirements in the Wanted forum.

--

To write the script yourself (since you say both)...

You'll want llSetText for the floating text. You'll also need to use an invisible prim attached at the waist or root, so that it covers the whole body easily and regardless of pose/movement.

To my mind your options for the paragraph are going to be dumping to chat (ideally IM, not local) or giving a Notecard.

All can be done via script using the event touch_start.

Link to comment
Share on other sites

Hi Freya,

Thank you for your help ...

Actually I want to learn scripting..But the problem is that I read the LSL wiki ..and  I am not able to find how can i start script in a new script.. I can find only some functions ..And I dont know how to make it as one for my need.

I dont know the technical term for all these things ..for eg : If i want to display information aftter touch ...I dont know how to search it in witki..and I found so many functions to display ..so I am confused .. How to start ..how the control move ...etc ..

So I just asked like as that in my previous post ...

Hope i get a help to start the things ..

Link to comment
Share on other sites

No problem, I was unclear with what you were wanting from this thread. Always good to check your expectations are in-line.

I've already linked you to most of the functions you'll need, but it can be good to study both the events and functions pages in the LSL wiki.

This quick script will run llSetText on state_entry. state_entry is the event that is triggered as soon as the script is Saved (and compiled automatically).

default{    state_entry()    {        llSetText("Hello, world!",<1,1,1>,0.5); //This text will be displayed above the object with the script inside.    }}

Note that llSetText is not suitable for displaying much text - it has a limit of 128 characters.

 This next script below  - first written by Eric Linden - is the "Hello World" script generated by clicking New Script inside an object in-world. When you click the object, it will say "Touched." in local chat. I'll add comments to clarify how it's being processed:-

default{    state_entry() //On initialisation...    {        llSay(0,"Hello, avatar!"); //Say "Hello, avatar!" in local chat.    }    touch_start(integer num_detected) //When this object is touched/clicked...    {         llSay(0,"Touched."); //Say "Touched."    }}

 You might also want to check out the example scripts for each function - they will usually tell you how to use the function to output the things you want.

Link to comment
Share on other sites

Hi,

 

I found something i wiki as follows

<lsl>//Give a notecard to anyone touching this object default {

   touch_start(integer total_number)   {       // get the UUID of the person touching this object       key user = llDetectedKey(0);       // Give them the first notecard found in the object's contents       llGiveInventory(user, llGetInventoryName(INVENTORY_NOTECARD, 0) );   }

}</lsl>

 

Here I got many doubts ..

what is </lsl> 

Where we shoud put this if i create my own new script .

In this script  INVENTORY_NOTECARD is the name of the notecard that we created and put it in inworld inventory ? and give that notecard for the Avatar who touches the prim ?

user   ? means 

 

 

Link to comment
Share on other sites


trondheimtour wrote:


touch_start(integer total_number) { // get the UUID of the person touching this object key user = llDetectedKey(0); // Give them the first notecard found in the object's contents llGiveInventory(user, llGetInventoryName(INVENTORY_NOTECARD, 0) ); }

This script has one event (touch_start) and two lines of procedural code.

This sets the variable 'user' to the key of the avatar that clicks the object containing the script. You will need this key for the next line:-

This function gives the inventory item - it uses the key obtained and stored in 'user' and also llGetInventoryName, a function that returns the name of the inventory item of TYPE (set to INVENTORY_NOTECARD), at position (set to 0 - the first item in the list).

INVENTORY_NOTECARD is an inventory TYPE - others include INVENTORY_LANDMARK and INVENTORY_SOUND.

0 is 'item 0' - the first item (in alphabetical order) in the list of inventory by TYPE (which is INVENTORY_NOTECARD), therefore llGetInventoryName will always return the name of the first notecard in the Contents tab for the prim with the script inside.

Now to answer your questions...

  • I don't think you need to worry about <lsl> or </lsl> - these are written for another language.
  • This script would be inserted or pasted into a New Script, which you can generate by creating a prim in-world, then using the Edit tool to select the Contents tab, and finally clicking the New Script button.
  • As above, INVENTORY_NOTECARD is an inventory TYPE, if you already know the name of your notecard (e.g. it's named 'MyNotecard') you can simplify the second line (llGiveInventory) to simply:-
  • llGiveInventory(user, "MyNotecard");
  • 'user' is a variable, set to store data of type key. Keys are special types of data for uniquely identifying objects (or avatars) in-world.

Hope this helps!

  • Like 1
Link to comment
Share on other sites

Hi,

I have written this script as follows :

default
{
state_entry()
{
llSay(0, "Hello, Avatar!");
}

touch_start(integer total_number)
{
// get the UUID of the person touching this object
key user = llDetectedKey(0);
// Give them the first notecard found in the object's contents
llGiveInventory(user, "MyNotecard");
}
}

 

Also I created a new notecard in my inventory named as MyNotecard.

But when i run and touch the object , it give a warning 

Unable to give inventory: 'No item named 'MyNotecard'.'.

 

Actually what might be the problem here .

Link to comment
Share on other sites


trondheimtour wrote:

Unable to give inventory: 'No item named 'MyNotecard'.'.

1. The function llGiveInventory searches the inventory of the object where the script is located (the Contents tab) - it does not search your own inventory (accessed via Ctrl+I).

You will need to put 'MyNotecard' inside the object that contains your script.

1a. And remember, should you change the name of MyNotecard, you will need to update your script to the new name (using llGetInventoryName(INVENTORY_NOTECARD,0); would've avoided this).

2. You no longer need llSay(0,"Hello, Avatar!"); - you can remove this from your script. If you're still planning on using llSetText to create floating text above your head, it can go in the place of this line.

3. Use the Code button when pasting LSL to this forum.

AddCode.jpg

Otherwise though, it's coming along well. Good work!

  • Like 1
Link to comment
Share on other sites

Hi ..

I am cofused with this ...

I put the Notecard inside the object which I created. The object is just a box .And then I put my new notecard under the created object in the inventory ..

But I dont understand the second thing you mentioned. The name of my notecard is MYNotecard

The script is just  New Script  .I didnt change the name of the script .

And where should i use this function llGetInventoryName (INVENTORY_NOTECARD,0 )  

Now I am getting the same error 

Link to comment
Share on other sites


trondheimtour wrote:

But I dont understand the second thing you mentioned. The name of my notecard is MYNotecard

In that case your script should also reference "MYNotecard" on the llGiveInventory line. Case is important - "myNotecard" is not the same as "mynotecard" or "MyNoTeCaRd".

The second thing, I assume, was item 1a - llGetInventoryName. I explained this function a few posts ago (how it uses INVENTORY_NOTECARD as a TYPE to return the first notecard alphabetically within the object's inventory (Contents tab). Using llGetInventoryName as you pasted it - also above - within llGiveInventory would enable you to ignore the name of the notecard, as the script would 'find' a notecard automatically so long as one was inside the object's inventory.

Whether you use an explcit name (such as "MYNotecard") or a function that returns the same value (llGetInventoryName) is up to you. I mentioned it as an option - if it's confusing, stick with whichever method you're most familiar with.

 On a personal note I won't be able to post further help until Monday or Tuesday next week - again, I suggest you check out the example scripts on the Wiki links I've been posting and try and work out how functions return values that can be used in scripts. Best of luck!

Link to comment
Share on other sites

You might find it easier to have the script read the name of the first (and, we hope, only) notecard in the prim's inventory.    That way you don't have to worry about spelling and capitisation, and you can even change the name of the notecard completely.

It's a little more complicated but saves time in the long run.

Try something like this:

string strNotecard;  //This is a global variable.   Because I have declared it up here, before default, I can reference it anywhere in the scriptdefault{	state_entry()	{		//state entry runs once, when the script starts		strNotecard = llGetInventoryName(INVENTORY_NOTECARD,0);		//In English, "Let 'strNotecard' stand for the name of the first notecard in the prim's inventory, whatever that is.   When LSL scripts count, they start from 0, not 1.		if(llGetInventoryType(strNotecard)!=INVENTORY_NOTECARD){		//sanity check -- "if there is no notecard in the prim's inventory"		llOwnerSay("There is no notecard in my inventory!");//complain about it.		}		else { //confirm to my owner that I know what I'm supposed to be doing.			llOwnerSay("I have found a notecard called "+strNotecard+" and I will give that to whoever touches me.");		}	}	touch_start(integer num_detected)	{		if(strNotecard){ //shorthand for "if a value has been assigned to strNotecard" -- in other words, if it has a name		llGiveInventory(llDetectedKey(0), strNotecard); //give a copy to whoever touches me		}	}	changed(integer change) 	{ //something has changed!  I wonder what		if(change & CHANGED_INVENTORY){//something in my inventory has changed!			llResetScript();//this makes state_entry run again, thus checking the notecard name in case you've changed it.			//You don't actually need this event, but it's good practice to include it in a script like this, to make sure the value of strNotecard is kept current.		}			}}

 

  • Like 1
Link to comment
Share on other sites

Hi,

I put the above script inside my object . Also I have a notecard in the subject. But there is no output when I touch the object. 

How  can i take the output with this script. 

Is there anything more I should do here in the object . I am sorry ...I dont know what to do here next.

Link to comment
Share on other sites

I have no idea what the problem is.   I have just tested the script in-world and it works OK.   I have sent you a copy of the object I used to test it .

Are you sure you are in an area where scripts are allowed to run?   Are you sure the script is, in fact, running?  If you have tried to save it previously and it contained an error, it will have saved as not running -- you can check by opening the script and examining the box at the bottom left:

Capture.PNG

If you can't get it to work, send me your copy (full perms) and I will try to see what the problem is.

  • Like 1
Link to comment
Share on other sites

Hi,

I copied the object to inventory and save the script . Also created as notecard inside the same object. 

Below shows the screenshot.

communityhelp.png

 

Here avaobj is the object i created . But i can see that after copying the script to inventory the ' Running ' option was not there ... I dont know how it happens . What i did here is I created a new object . Then take copy of that object to inventory . Then i changed the script . But Running option was not there . Before I copy to inventory Running option was there . Then the result was like , No Notecard found in the inventory . So i copied the object to inventory . Then Running option disappeared . 

I dont know why this happens . :(

Link to comment
Share on other sites

Scripts can only run if they are inside objects that are rezzed in-world.

So, what I suggest you do is go to somewhere you know you can run scripts and then rez a prim.

With the prim selected in edit mode, click on the "Object" tab of the editor (the last tab on the right).

Drag both the script and the card from your avaobj folder into the prim's object tab.

If you now open the copy of the script that is in the prim (not the copy in your inventory) you will see it it has a "running" box.

Now, if you touch the prim that contains the script and card, it should give you a copy of the card.

  • Like 1
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 3372 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...