Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Lucky Dip Script HELP!!!

Willy Scribe
Registered User
Join date: 26 Aug 2008
Posts: 2
07-19-2009 22:30
Hi I've been writing this lucky dip script below.. Was wondering if anyone had time to check why it isn't working?

I had it working but wanted to add a message to say if there wasn't' any objects in the item when someone clicked on it and then for the pay button to then light up.

Thanks for you're time

Willy...

[CODE]
integer payprice = 1;
integer total_number;
default
{

touch_start(integer total_number)
{
llWhisper(0, "Click to play the Lucky Dip";);
if(llGetInventoryName(INVENTORY_OBJECT,0)!=0);
{
llSay(0, "Sorry all prizes have been given out. More will be added shortly";);
}
}
state_entry()
{
llSetPayPrice(payprice, [PAY_HIDE, PAY_HIDE, PAY_HIDE, PAY_HIDE]);
llSetTimerEvent(5);

llSay(0, "Pay: L$"+(string)payprice); //add please Pay $40 to play the Lucky Dip

money(key giver, integer amount) {
//llSay(0, "Thanks for the " + (string)amount + "L$, " + llKey2Name(giver));

{
integer total = llGetInventoryNumber(INVENTORY_OBJECT);
if(llGetInventoryName(INVENTORY_OBJECT,0)!="";){llGiveInventory(giver,llGetInventoryName(INVENTORY_OBJECT,(integer)llFrand(total)));}
else
llWhisper(0,"Thanks for playing Lucky Dip!";);
}
}
}
}
[/CODE]
Dora Gustafson
Registered User
Join date: 13 Mar 2007
Posts: 779
07-20-2009 01:28
In what way isn't it working? Does it not compile? What do you want it to do that it does not? Is it doing it wrong or not at all? Mind reading is not my best:)
A little prayer: A more tidy code (matching brackets you know) would make it more pleasant to read and easier to debug.
_____________________
From Studio Dora
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
07-20-2009 05:32
first up, don't use font tags to surround php or code brackets, it breaks the formatting on the post. (but thanks for at least trying to include them)

second up, choose a consistent style of bracket placement, and indentation for the code inside the brackets as this will help you find this sort of mistake easier.

since it's brackets you're having trouble with I went with the brackets on their own line style. and fixed a bit of the spacing and indentation to give you an idea.

CODE

integer payprice = 1;
integer total_number;
default
{
touch_start( integer total_number )
{
llWhisper(0, "Click to play the Lucky Dip");
if (llGetInventoryName (INVENTORY_OBJECT, 0 ) != 0 );
{
llSay( 0, "Sorry all prizes have been given out. More will be added shortly" );
}
}

state_entry()
{
llSetPayPrice (payprice, [PAY_HIDE, PAY_HIDE, PAY_HIDE, PAY_HIDE] );
llSetTimerEvent(5);

llSay( 0, "Pay: L$" + (string)payprice ); //add please Pay $40 to play the Lucky Dip
} //-- missing bracket inserted

money( key giver, integer amount )
{
//llSay(0, "Thanks for the " + (string)amount + "L$, " + llKey2Name(giver));

{ //-- extra bracket not really needed, but not harmful
integer total = llGetInventoryNumber( INVENTORY_OBJECT );
if (llGetInventoryName( INVENTORY_OBJECT, 0 ) != "")
{
llGiveInventory( giver, llGetInventoryName( INVENTORY_OBJECT,(integer)llFrand( total ) ) );
}
else
{ //-- missing bracket inserted
llWhisper( 0, "Thanks for playing Lucky Dip!" );
}
} //-- extra bracket not really needed, but not harmful
}
}
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
Tali Rosca
Plywood Whisperer
Join date: 6 Feb 2007
Posts: 767
07-20-2009 05:34
One thing, at least, is a syntax error, indeed in the matching of brackets: You have your money event inside your state_entry event.
One of the brackets from the barrage at the end should be moved up to close your state_entry before you define your money.

Whether the script will then do what you want is a different matter. For one thing, I see you have a llSetTimerEvent(5) but no actual timer event to do something. While the script can compile with that, it hints that something is missing. (Or the llSetTimerEvent is an unnecessary leftover).

ETA: I see Void stepped through all the brackets while I was typing. :-)
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
07-20-2009 06:33
now that I'm looking closer at it there's a lot of bad code in there (the first if tests against 0 instead of "", when it should really be checking number against 0, extra global variable that's not used, a do nothing timer) and some poor logic (a pay message that only fires when the script starts, and an else statement that only fires if there is nothing left thus ripping off the user)

only the first thing in there should prevent a compile...

basic suggestions for changes:
remove the second global variable.

first if to check if there are object to give out with
if (llGetInventoryNumber( INVENTORY_OBJECT))
and if none are found move to a state without a money handler. and it really belongs in the state entry.

the llsay after the set timer needs to move to a timer event.

the script should REtest if there are objects inside of it after every give (or just test a decremented variable of the object count) and work as the first test does.
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
Willy Scribe
Registered User
Join date: 26 Aug 2008
Posts: 2
07-20-2009 07:35
Ah great thanks for that. Will put in a reset :). Thanks for you're help.
ab Vanmoer
Registered User
Join date: 28 Nov 2006
Posts: 131
07-20-2009 10:24
Without going through the code in detail, it appears that this is intended as some kind of scam.
Basically you are asking people to pay L$40 to play and if there is no inventory all you do is say thanks for playing.
If its not intended as a scam, then you need refund the payment:
llGiveMoney(giver,amount);