LSL Wiki Mirror 10-5-2006: llGiveMoney

HomePage :: PageIndex :: RecentChanges :: RecentlyCommented :: UserSettings ::
llGiveMoney(key destination, integer amount)

Transfers amount of Linden dollars from the script owner to destination. Requires the PERMISSION_DEBIT run-time permission.

destination can only be an avatar, not an an object or a group. The recipient does not need to be in the same sim as the object. If amount is less than or equal to zero, the object will say "Invalid parameter in llGiveMoney()." This looks pretty unprofessional, so if you're writing a vendor script that gives change (for example), you'll probably want to avoid it.

Older versions of the LSL documentation stated that llGiveMoney returned an integer. If the owner has insufficient funds to cover the llGiveMoney call, an error will appear on the user's screen, but there will be no data returned to the script itself. The return integer from llGiveMoney is always zero.

This example script gains the PERMISSION_DEBIT permission on startup and then gives L$1 to anyone who touches it.

default
{
     state_entry()
     {
          llRequestPermissions(llGetOwner(),PERMISSION_DEBIT);
     }

     touch_start(integer num_detected)
     {
          llGiveMoney(llDetectedKey(0),1);
     }
}

For an additional example, see ExampleMoney.

Q: What happens if the owner doesn't have enough funds to satisfy the llGiveMoney request?
A: The script pops up an error dialog stating "Insufficient funds". Because there isn't any return value from llGiveMoney, you need to keep track of money inside your script. This can be difficult to accomplish. There's no direct way to get your script to know whether or not it's out of money, but it'll keep telling the owner that it's out.
As KellyLinden explains: "It is not possible for llGiveMoney to return a meaningful value, the data is simply not available when and where it would be needed to make that happen."

Q: Wait, it returns zero? Are you sure it doesn't actually return nothing? Maybe you're doing it wrong.
A: Nope, it definitely returns zero, and it does so every time.

When llGiveMoney fails due to "Insufficient Funds", the script is not delayed: The error appears to the owner and noone else, and the script continues to function without any delay or conflict.

To receive money, use the money event.


Functions | Agent/Avatar
There are 5 comments on this page. [Display comments/form]