Jump to content

Some Help with a script


Laufiair Hexicola
 Share

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

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

Recommended Posts

Morning everyone, I've put together a script that slideshows images(which works as it's intended to). Now, I'm trying to add in a function so that when an image is shown, it allows a user to click it and get a notecard. Attempted using the similar method used for the images, but for some reason that's not working. Tells me function call mismatch for llgiveinventory.  I did try to move the notes list to the touch_start, but that didn't change anything. Something that should be simple has once again proved to be difficult, so I come to the forum asking for help.

Thanks, Logan


list slides = ["24d13f9a-a8ea-28dd-b6d1-d4cb0d5215f8", //Akai Hane Texture
               "064bacee-ab78-a16f-d278-1ae4fcda65ff"  //Starlight Construction Texture
               ];
               
list notes = ["",                                    //Akai Hane Infocard
              "718d00be-2696-9124-48e3-9f1841059316" //Starlight Construction Infocard
             ];               
            
integer index;

newSlide()
{
    string texture = llList2String(slides,index);
    llSetTexture(texture,1);
    index++;
    
    if(index>=llGetListLength(slides) )
       index = 0;
    
    if(index>=llGetListLength(notes) )
       index = 1;
}

default
{
    state_entry()
    {
        llSetTimerEvent(7);
        index = 0;
        index = 1;
        newSlide();
    }
    
    touch_start(integer num)
    {
        index = 1;
        key id = llDetectedKey(0);
        llGiveInventory(id, (list)notes);
    }

    timer()
    {
        newSlide();
    }
}

 

Link to comment
Share on other sites

The problem is with llGiveInventory, which, as you will see from the Wiki article, gives one named item.   You can't use it to give several items at once.   So you would have to loop through the list doing something like this:

integer counter = 0;
integer max = llGetListLength(notes);
do{
	llGiveInventory(id,llList2String(notes,counter));
}
while(++counter < max);

An alternative, since the notecards will presumably be copyable by the owner of the giver object, would be to use llGiveInventoryList, which would give them all at once, in a folder.

Link to comment
Share on other sites

38 minutes ago, Innula Zenovka said:

The problem is with llGiveInventory, which, as you will see from the Wiki article, gives one named item.   You can't use it to give several items at once.   So you would have to loop through the list doing something like this:


integer counter = 0;
integer max = llGetListLength(notes);
do{
	llGiveInventory(id,llList2String(notes,counter));
}
while(++counter < max);

An alternative, since the notecards will presumably be copyable by the owner of the giver object, would be to use llGiveInventoryList, which would give them all at once, in a folder.

Thanks for replying and yeah, I was reading about that - only I don't want to give several items at once nor do i want it to give a notecard to a person in a folder. When a texture is displayed, i want it to give a notecard for that texture only - so only one notecard.

Link to comment
Share on other sites

33 minutes ago, Laufiair Hexicola said:

When a texture is displayed, i want it to give a notecard for that texture only - so only one notecard.

Well, since you already know which texture is being displayed (that's what your number "index" is), then all you have to do is

llGiveInventory(llDetectedKey(0), llList2String(notes,index));

You'll want to go back and clean up the state_entry and touch_start events by getting rid of those unnecessary lines that say index = 0 and index = 1. You could simplify the newSlide function too, although it is working now.

Link to comment
Share on other sites

Ah, thanks.  Now I begin to understand the logic of your script, though it's not entirely clear to me if it's supposed to loop through the textures all the time, or only to run when someone touches it.   I'll assume it runs only when someone touches it, since that's simpler.

In that case, I would do something like this.  First I would create some new variables, 

integer iCounter;
integer iListLength;
key kToucher;

integer iCounter;
integer iListLength;
key kToucher;

then I would rewrite the userfunction newSlide()

newSlide()
{

	if(iCounter<iListLength){
		llSetTexture(llList2Key(slides,iCounter),1);
	  	llGiveInventory(kToucher, llList2String(notes,iCounter));
	  	++iCounter;//advance the counter
	}
	else{
		llSetTimerEvent(0.0);//stop the display
		iCounter = 0; // zero the counter
	} 	

}

and then, in the main script, do something like this 

default
{
    state_entry()
    {
    	iListLength = llGetListLength(slides);

    }


    touch_start(integer num)
    {
        iCounter = 0;
        kToucher = llDetectedKey(0);
        newSlide();
        llSetTimerEvent(7.0);
  		
    }

    timer()
    {
        newSlide();
    }
}

I've not tested it but that looks right to me.

HOWEVER ... I would take another look at your list notes, since llGiveInventory expects the name of the inventory item it is to give.  So I think that notes needs the actual names of the notecards.

 

Link to comment
Share on other sites

1 minute ago, Rolig Loon said:

Well, since you already know which texture is being displayed (that's what your number "index" is), then all you have to do is

llGiveInventory(llDetectedKey(0), llList2String(notes,index));

You'll want to go back and clean up the state_entry and touch_start events by getting rid of those unnecessary lines that say index = 0 and index = 1. You could simplify the newSlide function too, although it is working now.

Thank you, I thought I was missing something simple, just wasn't sure - and that was it. Script works now. Thanks again folks.

Link to comment
Share on other sites

1 minute ago, Innula Zenovka said:

Ah, thanks.  Now I begin to understand the logic of your script, though it's not entirely clear to me if it's supposed to loop through the textures all the time, or only to run when someone touches it.   I'll assume it runs only when someone touches it, since that's simpler.

In that case, I would do something like this.  First I would create some new variables, 

integer iCounter;
integer iListLength;
key kToucher;


integer iCounter;
integer iListLength;
key kToucher;

then I would rewrite the userfunction newSlide()


newSlide()
{

	if(iCounter<iListLength){
		llSetTexture(llList2Key(slides,iCounter),1);
	  	llGiveInventory(kToucher, llList2String(notes,iCounter));
	  	++iCounter;//advance the counter
	}
	else{
		llSetTimerEvent(0.0);//stop the display
		iCounter = 0; // zero the counter
	} 	

}

and then, in the main script, do something like this 


default
{
    state_entry()
    {
    	iListLength = llGetListLength(slides);

    }


    touch_start(integer num)
    {
        iCounter = 0;
        kToucher = llDetectedKey(0);
        newSlide();
        llSetTimerEvent(7.0);
  		
    }

    timer()
    {
        newSlide();
    }
}

I've not tested it but that looks right to me.

HOWEVER ... I would take another look at your list notes, since llGiveInventory expects the name of the inventory item it is to give.  So I think that notes needs the actual names of the notecards.

 

no it's designed to run through automatically, like a scrolling adboard, so if someone is interested in what the texture displays, they click it and are given the relevant notecard. Rolig nailed it - I figured there was something in the call to give the card, but just wasn't sure what. Now I know ^.^

Link to comment
Share on other sites

As Innula pointed out you can't give multiple items at once using llGiveInventory and should use llGiveInventoryList instead.  However that doesn't seem to be the only issue you have with your script.

For a start llGiveInventory doesn't work with UUIDs so unless "718d00be-2696-9124-48e3-9f1841059316" is the name of the notecard in the objects inventory (llGiveInventory will only work if the asset you're giving is in the contents of the object giving it) then the script will still fail.  Similarly since the first entry in your notecards list is an empty string the command will fail when attempting to give the first item in the list.

To be honest the script that you have at the moment is a little confusing since you seem to be changing the value of index for no apparent reason (for example in your state_entry event you set it to 0 then immediately after you change it to a value of 1).

If I were you I'd probably simplify the whole process by including both the textures and the notecards in the objects inventory and giving each texture and accompanying notecard similar names such as "Starlight Construction" for the texture and "Starlight Construction Infocard" for the notecard, then you simply need to cycle through the textures and when the user touches the object you can give them the correct notecard by appending " Infocard" to the name of the currently displayed texture.

so your object inventory would look like this...

SLObjectInventory.JPG.21ae518b357304ab91800dc915cd39da.JPG

and your script would be...

list slides = ["Akai Hane", "Starlight Construction"];
                           
integer index;
string texture;

newSlide()
{
    texture = llList2String(slides,index);
    llSetTexture(texture,1);
    index++;
    
    if(index>=llGetListLength(slides) )
       index = 0;
}

default
{
    state_entry()
    {
        llSetTimerEvent(7);
        index = 0;
        newSlide();
    }
    
    touch_start(integer num)
    {
        key id = llDetectedKey(0);
        string notecard = texture+" Infocard";
        if (llGetInventoryType(notecard) != -1) //Check to see if notecard exists in object inventory
        {
            llGiveInventory(id, notecard);
        }
    }

    timer()
    {
        newSlide();
    }
}

 

Edited by Fluffy Sharkfin
  • Thanks 1
Link to comment
Share on other sites

Neat.  As Innula said, though, you should probably use the names of your two notecards rather than their UUIDs. You can get away with using UUIDs, but if you ever revise the notecards, I'm pretty sure those UUIDs will change, which means your unit will stop working.

  • Like 1
Link to comment
Share on other sites

2 minutes ago, Rolig Loon said:

Neat.  As Innula said, though, you should probably use the names of your two notecards rather than their UUIDs. You can get away with using UUIDs, but if you ever revise the notecards, I'm pretty sure those UUIDs will change, which means your unit will stop working.

So llGiveInventory does work with UUIDs?  Interesting, there doesn't seem to be any mention of that on the wiki, thanks for the info Rolig.

Link to comment
Share on other sites

Yep going to follow Fluffy and Innula's suggestions - as soon as I changed the llgiveinventory, it tried to find the cards as objects rather then notecards. I've always been able to use uuid's with llgiveinventory, but only static not dynamic. I was trying to piece together a script I thought was going to be simple and ended up being overly complex. Fluffy's script and setup works(thank you for that) and reminds me of how the halovends were setup.

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 2331 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...