S.O.S. to Jeff Gomez or an Omega!
|
Douglas Callahan
Fresh Prince Of SL
Join date: 2 Jul 2004
Posts: 349
|
04-23-2005 20:06
I don't know if my last thread got deleted or something, because noone responded. I'm trying to get this script to work. It's supposed to give notecard when touched to the toucher (which it does fine), and give a notecard, that is dropped on it by anyone, to the owner, and then delete said note from its inventory. However, it simply allows someone to drop in a note, and then it sends the owner the notecard that is supposed to go to people when they touch it (Suggestion Scroll) and then deletes this. How can I get it to give the new notecard to the owner and delete it after, while not affecting the Suggestion Scroll? Here's the code: default { state_entry() { llAllowInventoryDrop(TRUE); }
touch_start(integer total_number) { llGiveInventory(llDetectedKey(0), "Suggestion Scroll"); if ( llGetInventoryNumber(INVENTORY_SOUND) > 0 ) { llTriggerSound("Button_click_down", 1.0); } } changed(integer change) { if ( change && CHANGED_ALLOWED_DROP ) { integer num = llGetInventoryNumber(INVENTORY_NOTECARD); string name = llGetInventoryName(INVENTORY_NOTECARD,num - 1); llGiveInventory(llGetOwner(), name); llInstantMessage(llGetOwner(), "Scroll Delivery"); llRemoveInventory(name); } } }
_____________________
Other than that, Mrs. Lincoln, how was the play?
|
Jeffrey Gomez
Cubed™
Join date: 11 Jun 2004
Posts: 3,522
|
04-23-2005 23:06
Sorry about that. Had to take care of a little drama thread in General. Let's see if I get this straight - your notecards are miscommunicating, so it's sending the wrong notecard? Well, that's easy! string note_name = "Name Of Notecard Here";
default { state_entry() { llAllowInventoryDrop(TRUE); }
touch_start(integer total_number) { llGiveInventory(llDetectedKey(0), "Suggestion Scroll"); if ( llGetInventoryNumber(INVENTORY_SOUND) > 0 ) { llTriggerSound("Button_click_down", 1.0); } } changed(integer change) { if ( change && CHANGED_INVENTORY_DROP ) { integer num = llGetInventoryNumber(INVENTORY_NOTECARD); integer i; for(i = 0; i < num; i++) { string name = llGetInventoryName(INVENTORY_NOTECARD,i); if(name != note_name) { llGiveInventory(llGetOwner(), name); llInstantMessage(llGetOwner(), "Scroll Delivery"); llRemoveInventory(name); } } } } }
Basically, just plug in the name of the note you don't want to send and you're good to go.  Edit: Strike last edit. CHANGED_INVENTORY_DROP is correct.
_____________________
---
|
Douglas Callahan
Fresh Prince Of SL
Join date: 2 Jul 2004
Posts: 349
|
04-23-2005 23:56
if(name != note_name) { llGiveInventory(llGetOwner(), name); llInstantMessage(llGetOwner(), "Scroll Delivery"); llRemoveInventory(name); } Well, what hapens if the name is the notecard, how do I get it to find the other one?
_____________________
Other than that, Mrs. Lincoln, how was the play?
|
Catherine Omega
Geometry Ninja
Join date: 10 Jan 2003
Posts: 2,053
|
04-24-2005 00:10
From: Douglas Callahan Well, what hapens if the name is the notecard, how do I get it to find the other one? The for loop will run through all notecards, comparing them against the correct name. If it matches the one you DO want to send, it'll send it, otherwise, it'll do nothing. for(i = 0; i < num; i++) In this code, the script declares the value of i to be 0, that it's less than the value of num, and then increments it by one. (++) So in the context of the for loop, it'll check if i is less than num, then run though everything contained within the braces following the for statement, then increment i, then do it again.
|
Douglas Callahan
Fresh Prince Of SL
Join date: 2 Jul 2004
Posts: 349
|
Thankyou
04-24-2005 00:19
okay, thanks alot guys! And thankyou for explaining the i++ Catharine  . I had been wondering what that was for a while.
_____________________
Other than that, Mrs. Lincoln, how was the play?
|
Catherine Omega
Geometry Ninja
Join date: 10 Jan 2003
Posts: 2,053
|
04-24-2005 00:47
That's the joke of C++... it's one more than C. 
|
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
|
04-24-2005 04:30
pffft What about the Onizuka's? a little typo in the changed contional, would result in wasted cpu time. changed it to use a while loop. ran the risk of skipping a notecard, and throwing inventory errors. string note_name = "Name Of Notecard Here";
default { state_entry() { llAllowInventoryDrop(TRUE); }
touch_start(integer total_number) { llGiveInventory(llDetectedKey(0), "Suggestion Scroll"); if ( llGetInventoryNumber(INVENTORY_SOUND) > 0 ) { llTriggerSound("Button_click_down", 1.0); } } changed(integer change) { if ( change & CHANGED_INVENTORY_DROP ) { integer num = llGetInventoryNumber(INVENTORY_NOTECARD); integer i = 0; while(i < num) { string name = llGetInventoryName(INVENTORY_NOTECARD,i); if(name != note_name) { llGiveInventory(llGetOwner(), name); llRemoveInventory(name); llInstantMessage(llGetOwner(), "Scroll Delivery"); --num; } else { ++i; } } } } }
_____________________
Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river. - Cyril Connolly
Without the political will to find common ground, the continual friction of tactic and counter tactic, only creates suspicion and hatred and vengeance, and perpetuates the cycle of violence. - James Nachtwey
|
Jeffrey Gomez
Cubed™
Join date: 11 Jun 2004
Posts: 3,522
|
04-24-2005 08:48
Whoops! Yep. Forgot about that. 
_____________________
---
|
Douglas Callahan
Fresh Prince Of SL
Join date: 2 Jul 2004
Posts: 349
|
04-24-2005 20:45
whats the difference between the two? and will it matter about skipping a notecard if there will only be two in there since it deletes itself, leaving one?
_____________________
Other than that, Mrs. Lincoln, how was the play?
|
Jeffrey Gomez
Cubed™
Join date: 11 Jun 2004
Posts: 3,522
|
04-24-2005 21:32
Yep. I forgot that when you "remove" that notecard from inventory, it also shortens the list (1) and makes the next notecard up that number (2). The rewrite Strife put together fixes that problem by accounting for the list getting shorter (--n) and does not add to the counter variable, i, allowing the script to check the notecard that is now in that slot. By the way, minor tip. You might be a little confused about the usage of i++ versus --n, or rather, why the difference in where the pluses and minuses are placed matters. To sort of clear that up, here's an example in standard C++. I'm not sure if it works in LSL. integer i = 0;
// This will evaluate as zero in variable j and add one to i. j = i++;
i = 0; // Reset i for sake of example
// While this will evaluate to one in variable j and add one to i. j = ++i;
Basically, it's just order of operations. Putting the pluses (or minuses) first means you do that operation first. Putting them after means you do that operation second.
_____________________
---
|
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
|
04-24-2005 22:13
if you don't care about the value returned by the ++ or -- operation then put it before the variable. you save 5 bytes and a memory lookup, end result being: your script runs faster.
_____________________
Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river. - Cyril Connolly
Without the political will to find common ground, the continual friction of tactic and counter tactic, only creates suspicion and hatred and vengeance, and perpetuates the cycle of violence. - James Nachtwey
|