Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Help with notecard vendor script

Phenicia Gravois
Registered User
Join date: 3 Nov 2008
Posts: 70
04-17-2009 07:07
I am having trouble getting the following script to work when i place it in an object to give a notecard on "touch". What do i need to do to make it work? It doesn't give out any notecards at all.

// Gives a note to a person clicking on it.
//


default
{
state_entry()
{

}

touch_start(integer total_number)
{
// Find out who clicked, and give them a note
key giver;
giver = llDetectedKey(0);
string name = llDetectedName(0);

if (giver != NULL_KEY) {
integer InvNum;
string NoteName;
integer NumCards = llGetInventoryNumber(INVENTORY_NOTECARD);
for ( InvNum = 0; InvNum < NumCards; InvNum++) {
NoteName = llGetInventoryName(INVENTORY_NOTECARD, InvNum);
llGiveInventory(giver, NoteName);
}
}
}
}
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
04-17-2009 07:54
Your script works fine. Did you drop notecards in it? Are you on script enabled land?
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime.
From: someone
I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
Phenicia Gravois
Registered User
Join date: 3 Nov 2008
Posts: 70
04-17-2009 08:05
yes and yes

do i have to change anything in the script to name my notecard?
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
04-17-2009 08:11
From: Phenicia Gravois
yes and yes

do i have to change anything in the script to name my notecard?

Your script worked just like it is in world. It gave me the 4 notecards I had in the object.

Are you really giving more then one notecard? If not, then just do this:

CODE


default {
touch_start(integer total_number) {
llGiveInventory(llDetectedKey(0), llGetInventoryName(INVENTORY_NOTECARD, 0));
}
}

_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime.
From: someone
I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
04-17-2009 08:12
Make sure your script is running also.
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime.
From: someone
I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
Phenicia Gravois
Registered User
Join date: 3 Nov 2008
Posts: 70
04-17-2009 08:14
I am giving three notecards and the script is running yes. I'll keep trying, thanks for your help. :))
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
04-17-2009 15:54
are you set to busy mode?
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
Lazink Maeterlinck
Registered User
Join date: 8 Nov 2005
Posts: 332
04-17-2009 15:57
The script works, everyone who has looked at it and tested it says it does, so as void basically said, you have a setting that is not letting you receive the notecards. Busy mode, Away mode, are you using RLV... just a lot of things. But your script works just fine :)
Johan Laurasia
Fully Rezzed
Join date: 31 Oct 2006
Posts: 1,394
04-18-2009 00:53
Your script works fine, but you're going a little overboard with it, for example, you don't need the "if (giver != NULL_KEY)", as no one with a null key will ever touch the object, hence, there's no need to test for it. Also, you create unnecessary variables (string name = llDetectedName(0)), but you never wind up using it. I re-wrote script with the 'extra baggage' removed. Not tryin' to hammer on ya, just wanted to point out a few details so you can optimize the script a bit. In this day and age of script limits on the horizon, you want to code as efficiently as possible.

CODE

default
{
touch_start(integer total_number)
{
integer i;
string NoteName;
integer NumCards = llGetInventoryNumber(INVENTORY_NOTECARD);
for (i=0; i<NumCards;i++)
{
NoteName = llGetInventoryName(INVENTORY_NOTECARD,i);
llGiveInventory(llDetectedKey(0), NoteName);
}
}
}


hope that helps :)
_____________________
My tutes
http://www.youtube.com/johanlaurasia
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
04-18-2009 01:43
CODE

list cards;
default
{
state_entry()
{
integer i;
string NoteName;
integer NumCards = llGetInventoryNumber(INVENTORY_NOTECARD);
cards = [];
for (i=0; i<NumCards;i++)
{
NoteName = llGetInventoryName(INVENTORY_NOTECARD,i);
cards += NoteName;
}
}

touch_start(integer total_number)
{
key id = llDetectedKey(0);
string fn = llGetObjectName();
llGiveInventoryList(id,fn,cards);
}

changed(integer change)
{
if(change & CHANGED_INVENTORY)
{
llResetScript();
}
}
}
_____________________
Dark Heart Emporium

http://www.xstreetsl.com/modules.php?name=Marketplace&MerchantID=133020

want more layers for tattoos, specifically for the head? vote here
http://jira.secondlife.com/browse/VWR-1449?

llDetectedCollision* Functions similar to touch
http://jira.secondlife.com/browse/SVC-3369
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
04-18-2009 03:27
CODE

list gLstNotecarNames;
fCollectNotecards( ){
integer IStillHaveTo = llGetInventoryNumber( INVENTORY_NOTECARD );
@Through_Hoops;
gLstNotecarNames += llgetInventoryname( INVENTORY_NOTECARD, --IStillHaveTo );
if (IStillHaveTo) jump Through_Hoops;
}

default{
state_entry(){
fCollectNotecards();
}

touch_start( integer vIntTotalToches ){
llGiveInventoryList( llDetectedKey( 0 ), "notecards", gLstNotecarNames );
}

timer(){
llSetTimerEvent( 0.0 );
llResetScript();
}

changed( integer vBitChanges ){
if (CHANGED_INVENTORY & vBitChanges){
llSetTimerEvent( 10.0 );
}
}
}

nyah, now it waits 10 seconds before triggering the inventory collection of notecards and you don't have to manually clear the list.
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
04-18-2009 08:18
Lovely, Void. It works! (With the addition of a couple of semicolons and capitalizing in llGetInventoryName ;) ). And with a sense of humor too. :D
Lazink Maeterlinck
Registered User
Join date: 8 Nov 2005
Posts: 332
04-18-2009 15:31
Why the jump Void? Is it faster then a for loop, or even a while loop? Just curious :)
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
04-18-2009 15:41
From: Lazink Maeterlinck
Why the jump Void? Is it faster then a for loop, or even a while loop? Just curious :)

It is a sure fire way to promote a discussion in Scripting Tips. To put it mildly, "jump" ruffles the feathers of a lot of old school coders. To put it unmildly, some people have an almost paranoid hatred of it. You will hear descriptions of unprofessional, sloppy, dangerous, unreliable, silly etc.

I kinda of like it but have only used it once or twice in LSL. It was used in the only scripting language I knew for 30 years. Don't even remember what the language was called but it was for the old TI-95 magnetic strips.
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime.
From: someone
I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
Lazink Maeterlinck
Registered User
Join date: 8 Nov 2005
Posts: 332
04-18-2009 15:50
From: Jesse Barnett
It is a sure fire way to promote a discussion in Scripting Tips. To put it mildly, "jump" ruffles the feathers of a lot of old school coders. To put it unmildly, some people have an almost paranoid hatred of it. You will hear descriptions of unprofessional, sloppy, dangerous, unreliable, silly etc.

I kinda of like it but have only used it once or twice in LSL. It was used in the only scripting language I knew for 30 years. Don't even remember what the language was called but it was for the old TI-95 magnetic strips.


Oh, I know where Jumps come from, just don't see it often in LSL :) Why I was wondering why he used it. Just style? Show something different, just my morbid curiosity poking it's head out :)
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
04-18-2009 15:58
From: Lazink Maeterlinck
Oh, I know where Jumps come from, just don't see it often in LSL :) Why I was wondering why he used it. Just style? Show something different, just my morbid curiosity poking it's head out :)


Um.... any sense of humor?

if (IStillHaveTo) jump Through_Hoops;

is worth the price of admission, even if there are "better" ways to write the script. :p
Lazink Maeterlinck
Registered User
Join date: 8 Nov 2005
Posts: 332
04-18-2009 16:03
LOL, I don't read variable names like that :P just how the script functions. Makes more sense now :) hehe :)
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
04-18-2009 17:54
From: Lazink Maeterlinck
Why the jump Void? Is it faster then a for loop, or even a while loop? Just curious :)

it was before mono, I haven't tested since then.

loops in order of speed (slowest to fastest)
for (partly due to the extra variable frequently used I think)
while-do
do-while
jump-if
state_exit-state next; (which used to cause a crash and may soon be nixed)

@Roliq:
thanks, fixed now.

@all:
I used the jump loop structure because I wanted to include some humor, thanks to the thread in which several of us brought up programming humor. Plus it's an infrequently used optimization (even by me, I generally use do-while if possible).

I was tempted to use a second state and the state_exit loop, but state changes in mono are rather slow, (although the loop itself is fast now) and the likelihood of allowing state changes in state_exit being nixed (strife recently wrote the patch to kill it). never mind that's it's harder to make funny.

@Jump(goto) pro/con discussion:
jump has limited, Effective, use, of which this is one IMO. but it tends to get overused for other trivial things, by the inexperienced, that could be done much more easily, effectively, and legibly in other ways. for instance optional code segments that would be better served with a single if, or a user function.

batch file scripters will recognize the loop use of jump automatically, since it's pretty common there, or was. (and I'm still in the habit of automatically writing jump targets as :label because of it)
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -