Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Giver with llSameGroup?

Paul Wardark
Wait, what?
Join date: 10 Jan 2009
Posts: 383
08-21-2009 15:18
I have a script that works fine. It gives an object to people that are in the group only. Today I tried adding a second object to it. I broke it.

How would I replace the two llGiveInventorys with a single command?

CODE


default
{
touch_start(integer total_number)
{
integer i;

for (i = 0; i < total_number; i++)
{
if (llSameGroup(llDetectedKey(i))) // same as llDetectedGroup(i) (with llDetectedGroup, detected does not need to be in the sim)
llGiveInventory(llDetectedKey(i), "SpyBot - Freebie");
llGiveInventory(llDetectedKey(i), "FEMBOT");
else
llInstantMessage(llDetectedKey(0),"Make sure you're wearing the Wardark Industries Group tag before trying to claim your gifts.");
}
}
}

_____________________
Viktoria Dovgal
Join date: 29 Jul 2007
Posts: 3,593
08-21-2009 15:53
LSL carries over some strange little features from C, the {} brackets are optional in an if or else, but that assumes that only one statement follows. Indentation is only there for looks, it doesn't really do anything.

You can avoid the mess my pretending that the {} are not optional, add them even if the compiler wouldn't care.

CODE

if (llSameGroup(llDetectedKey(i))) { // same as llDetectedGroup(i) (with llDetectedGroup, detected does not need to be in the sim)
llGiveInventory(llDetectedKey(i), "SpyBot - Freebie");
llGiveInventory(llDetectedKey(i), "FEMBOT");
}
else {
llInstantMessage(llDetectedKey(0),"Make sure you're wearing the Wardark Industries Group tag before trying to claim your gifts.");
}


There is an llGiveInventoryList function you could use to combine those into one, but it has quirks. llGiveInventory works anywhere on the grid, llGiveInventoryList only works if the avatar is nearby. Given LL's occasional habit of "forgetting" that an avatar is online when it is time to send IMs or inventory, stick with llGiveInventory unless you're handing out a lot of stuff (and even then, you might want to box it up instead).