|
Over Sleeper
I Dream in LSL
Join date: 12 Jan 2006
Posts: 141
|
01-11-2007 16:39
I have a notecard name from an objects inventory. There are several notecards. I am trying to get the inventory number of the named notecard. I know I need to loop through all of the inventory items that are notecards until the name matches. But loops and fors, and whiles confuse me greatly. Could anyone lend a hand? Thanks
|
|
Osgeld Barmy
Registered User
Join date: 22 Mar 2005
Posts: 3,336
|
01-11-2007 21:27
integer total; integer current_place;
default { state_entry() { total = llGetInventoryNumber(INVENTORY_NOTECARD); do { whatever you want to do ++current_place; } while (current_place < total); } }
do-while loops are faster but here is the same thing in a for loop integer total; integer current_place;
default { state_entry() { total = llGetInventoryNumber(INVENTORY_NOTECARD); for (current_place = 0; current_place < total; ++current_place) { llStuff(); } } }
|
|
Over Sleeper
I Dream in LSL
Join date: 12 Jan 2006
Posts: 141
|
01-11-2007 21:40
Great!
So if I have a notecard named "My Colors" and I want to find its' inventory number, how can I work that in?
|
|
Osgeld Barmy
Registered User
Join date: 22 Mar 2005
Posts: 3,336
|
01-11-2007 21:51
integer total; integer current_place;
default { state_entry() { total = llGetInventoryNumber(INVENTORY_NOTECARD); do { if (llGetInventoryName(INVENTORY_NOTECARD, current_place) == "My Colors") { llOwnerSay("the notecard your looking for is number " + (string)current_place); current_place = total; } else ++current_place; } while (current_place < total); } }
dont forget that the count starts @ 0 so the 3rd notecard will report as 2 and ect
|
|
Domino Marama
Domino Designs
Join date: 22 Sep 2006
Posts: 1,126
|
01-12-2007 05:43
If you need it for a number of notecards then a function is probably a better way to solve this.
integer get_notecard_num(string name) { integer tI = llGetInventoryNumber(INVENTORY_NOTECARD); while ( tI ) { if ( llGetInventoryName(INVENTORY_NOTECARD, --tI ) == name ) { return tI; } } return -1; }
|