|
Khashai Steinbeck
A drop in the Biomass.
Join date: 15 Oct 2005
Posts: 283
|
06-15-2006 15:00
I am still very new to scripting. Most of what I do manage to make work, I use examples from either the library or the wiki, and then read through the related documents until I make whatever it is I am trying to do work. Now for my latest project (and this may already exist in the public domain), I was trying to make a script that used a FastPay dialog, and then when the item was paid for, gave the inventory as a folder. The first thing I did was to get the FastPay dialog to work (which was far easier than I expected), then I added the llGiveInventoryList thing, and... the FastPay stops working. Again I dont know what is wrong with the code, because I dont understand how the code is supposed to be laid out for this sort of operation. However, I believe the problem to be in the state. I think (and Im probably really wrong) that I need to tell the script to change state before the llGiveInventoryList happens... but every time I try to change it I end up with a syntax error. Below is the code... however, I am trying to learn LSL, so if you know how to fix it, please do so, but also tell me why it was changed, and how to avoid this type of problem in the future. Btw, I have never programmed before, so this is all very new to me.
default { money(key giver, integer amount) { integer CorrectAmount = 350; llSetPayPrice(PAY_HIDE, [350, PAY_HIDE, PAY_HIDE, PAY_HIDE]);//Set Correct Ammount.
if (amount == CorrectAmount) { list inventory; string name; integer num = llGetInventoryNumber(INVENTORY_ALL); string text = llGetObjectName() + " is unpacking...\n"; integer i; for (i = 0; i < num; ++i) { name = llGetInventoryName(INVENTORY_ALL, i); if(llGetInventoryPermMask(name, MASK_NEXT) & PERM_COPY) inventory += name; else llOwnerSay("Cannot give asset \""+name+"\", owner lacks copy permission"); llSetText(text + (string)((integer)(((i + 1.0) / num) * 100))+ "%", <1, 1, 1>, 1.0); } //chew off the end off the text message. text = llGetObjectName(); //we don't want to give them this script i = llListFindList(inventory, [llGetScriptName()]); inventory = llDeleteSubList(inventory, i, i); if (llGetListLength(inventory) < 1) llSay(0, "No items to offer."); else { llGiveInventoryList(llGetOwner(), text, inventory); llSetText("All done!\nYou can delete this now!",<1,1,1>,1); llOwnerSay("Your new "+ text +" can be found in your inventory, in a folder called '"+ text +"'."); } }
}
}
|
|
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
|
06-15-2006 15:11
The money event is triggered *after* the person has paid the object. So if you want the fast pay dialog to be presented the first time, you need to put the llSetPayPrice in state_entry or on_rez or something. Otherwise it will get set after the first person pays the object, so the first time you use this script, you won't get a fast pay dialog.
|
|
Sol Columbia
Ding! Level up
Join date: 24 Sep 2005
Posts: 91
|
06-15-2006 16:26
It would probably also be a good idea to put your inventory list making code in state_entry and/or on_rez so it just has to do it once rather than every time someone pays. You can add a changed event to run the inventory function also in case the contents is changed after you've started vending.
|
|
Khashai Steinbeck
A drop in the Biomass.
Join date: 15 Oct 2005
Posts: 283
|
06-15-2006 23:00
From: Ziggy Puff The money event is triggered *after* the person has paid the object. So if you want the fast pay dialog to be presented the first time, you need to put the llSetPayPrice in state_entry or on_rez or something. Otherwise it will get set after the first person pays the object, so the first time you use this script, you won't get a fast pay dialog. I read in the wiki that the "pay.." option requires the money() state.
|
|
Osgeld Barmy
Registered User
Join date: 22 Mar 2005
Posts: 3,336
|
06-15-2006 23:31
llSetPayPrice(PAY_HIDE, [350, PAY_HIDE, PAY_HIDE, PAY_HIDE]);
since this line is set in your money() event it doesnt take effect untill someone pays the object
llSetPayPrice isnt a money function, its more like a prim thing, so you can set it anywhere you want, as long as its defined before any money stuff comes up
(it doesnt set any price for LSL or the object, it just sets the output for the fast pay window, wich then triggers the money event)
|
|
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
|
06-16-2006 08:25
From: Khashai Steinbeck I read in the wiki that the "pay.." option requires the money() state. Yes, you need the money event to handle the money received, without it the payer won't get any inventory. So you're right. Most of the code in the money event needs to be there, *expect* for the part where you set the fast pay price, that code needs to be moved somewhere else. Something like: integer CorrectAmount = 350;
default { state_entry() { llSetPayPrice(PAY_HIDE, [CorrectAmount, PAY_HIDE, PAY_HIDE, PAY_HIDE]); //Set Correct Amount. Use the variable that you've already set up. This way, // if you want to change the price, you only have to change it in one place, // at the top of the script }
money() { if (amount == CorrectAmount) { ... the rest same as before } }
When you put that code in state_entry(), it gets executed as soon as the script starts. That ensures that the fast pay price is set on the prim befopre anyone comes to pay it. If you have the code in money(), it won't get called until someone pays it, so the first person paying it won't get the fast pay dialog, because you haven't set the fast pay price yet.
|