Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Please help, noob scripter stuck!

Devaya Rayna
Registered User
Join date: 7 Aug 2009
Posts: 3
10-07-2009 23:06
I usually am able to patch together my scripts from bits and pieces and with help from the forums and wiki get them to work.

With this I hit a block.

The script functions perfectly so far, but i need to add a new branch or condition.

Once listen begins, If someone tries to pay again or purchase, i need the script to:

1. continue listening.

and

2. Either not accept money... or, deliver an object from it's inventory.

I can get 1 or 2 to work but not both... any ideas?


//script follows


integer channel;

string name;

key id;

string message;

float timeout = 5.0;

integer handle;




default
{

money(key id, integer amount)

{
handle = llListen(-493, "", "", "";);
}
listen( integer channel, string name, key id, string message )
{
llOwnerSay("working";);



{
llInstantMessage(id, "Thank you. Please accept xxxx.";);

llGiveInventory(message,llGetInventoryName(INVENTORY_OBJECT, 0));

}
if (id = message)
{
llSetTimerEvent(timeout);
}

}



timer(){
llSetTimerEvent(0.0);
llListenControl(handle,FALSE);
llResetScript();
}
}
ab Vanmoer
Registered User
Join date: 28 Nov 2006
Posts: 131
10-07-2009 23:56
I really can't figure out what the script is supposed to be doing or what it is listening for, so it is rather hard to give advice.
To not accept money, you can either accept then automatically refund payments or change to a state that has no money event handler when you don't want to take payments.

You should also be careful of your equality comparisons:
Instead of:
if (id = message)
use:
if (id == message)
Devaya Rayna
Registered User
Join date: 7 Aug 2009
Posts: 3
10-08-2009 00:11
Sorry for my noobishness, but what is the difference between "id = message" and "id == message"?
ab Vanmoer
Registered User
Join date: 28 Nov 2006
Posts: 131
10-08-2009 00:55
if (id = message) means assign the value of 'message' to 'id' , then execute the if based on the the value of 'id'.
if (id == message) means if 'id' IS EQUAL TO 'message' which is probably what you want.
This catches almost everyone when they first start programming one of the C like languages of which LSL is one, so don't feel bad :)
Innula Zenovka
Registered User
Join date: 20 Jun 2007
Posts: 1,825
10-08-2009 06:08
The way the extracts of the script -- I assume they're extracts -- are presented here makes no sense, I'm afraid. You've got a listen event in the middle of the money event, for example, which isn't going to work.

Anyway, to my mind, the best way to stop it accepting money, once it's been paid, until it delivers the goods, is, as ab suggests, simply to switch states. Something on these lines should do it -- that way, you can't pay it in the listening state, because there's no money event. Something on these lines should do it

CODE
 key avatar;
integer handle;
integer my_channel = -491;
integer my_price = 50;
string goods = "name of my product";

default
{
state_entry(){
llSetPayPrice(PAY_HIDE,[my_price]);
}
money(key giver, integer amount){

if (amount == my_price){
avatar = giver;
state listening;
}
else{
//some sort of error handling in case you end up with the wrong amount -- which shouldn't happen but can.
//If it does, with the script set up like this, it may because someone's trying to hack your vendor, so
//I would suggest keeping the money and inviting the av to get in touch with you about a refund, rather than just refunding the money
}

}

}

state listening
{
state_entry(){
handle = llListen(my_channel,"",NULL_KEY,(string)avatar);
llListenControl(handle,TRUE);
}

listen(integer channel,string name, key id, string message){
llGiveInventory(avatar,goods);
llListenRemove(handle);
state default;
}
}
Devaya Rayna
Registered User
Join date: 7 Aug 2009
Posts: 3
Wow, thanks!
10-08-2009 12:18
TY Innula and Ab. I've gone from ramming my head against the desk to smiling and fist pumping cheers! YES!

Innula, the script I posted was complete. It was actually functioning. I am still trying to "get" state changes. I figured my script needed that. Because of the way it was written, it worked, but gave me no room to add functionality. And it took 2 scripts to acccomplish what your one did.

So I used your example and modified as needed -- I still have a listen event inside of a money event, (:o)

and the thing works! And much faster than my previous version! TY very much for helping me overcome this hurdle. I think this has gone a long way to helping me understand state changes.
Innula Zenovka
Registered User
Join date: 20 Jun 2007
Posts: 1,825
10-08-2009 12:51
Sorry, Devaya.. my mistake. I'd misread your original script, but now I see how the bracketing works. I'm still confused.. if I'm right in thinking that an object (which it has to be, since it's a negative channel) tells it the key of the av to whom it's to give its contents, I don't see how if(id==message) can ever be true. Anyway, glad you've got it working.