I'm Stumped again
|
|
Danx Daniels
Registered User
Join date: 22 Dec 2006
Posts: 99
|
12-22-2006 22:26
This seems like it should be a simple script. When the object is clicked I want it to open a menu with 2 buttons, one for getting paid, the other for nothing. But of course, I'm having problems. integer CHANNEL = 44; list MENU_MAIN = ["Nothing", "Collect"]; integer pay = 3; key playerID; default { state_entry() { llListen(CHANNEL, "", NULL_KEY, "" ); if(! ( llGetPermissions() & PERMISSION_DEBIT) ) { llRequestPermissions(llGetOwner(), PERMISSION_DEBIT) ; }
} touch_start(integer num_detected) { llDialog(llDetectedKey(0), "What is your wish?", MENU_MAIN, CHANNEL); } listen(integer amount, string name, key id, string message) { if (message == "Collect") { llSay(0, "You want to collect your pay!"); if (pay > 0) { llGiveMoney(playerID,1); } } else { } } }
I get an error Invalid parameter in llGiveMoney() when you click collect.
|
|
Peekay Semyorka
Registered User
Join date: 18 Nov 2006
Posts: 337
|
12-23-2006 02:03
In the example, "playerID" was never initialized to anything, so llGiveMoney() fails because it doesn't know who to pay.
When dealing with debit permissions you need to be very careful with setting (and resetting) variables when various conditions occur.
-peekay
|
|
Peekay Semyorka
Registered User
Join date: 18 Nov 2006
Posts: 337
|
12-23-2006 02:06
In the example, "playerID" was never initialized to anything, so llGiveMoney() fails because it doesn't know who to pay.
When dealing with debit permissions you need to be very careful with setting (and resetting) variables when various conditions occur.
-peekay
|
|
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
|
12-23-2006 02:26
As Peekay said you never set up playerID. I'm guessing this is just a fragment of a larger script? Setting up an open listen in state_entry isnt a good idea, should be only active when needed. Using a hardcoded channel number is also bad, if you have two of the games in close proximity they will interact.
|
|
Danx Daniels
Registered User
Join date: 22 Dec 2006
Posts: 99
|
Yes
12-23-2006 12:18
It is part of a much larger script. I did fix my problem and everything is running as it should.
|
|
Danx Daniels
Registered User
Join date: 22 Dec 2006
Posts: 99
|
grr
12-23-2006 12:44
And a few minutes later I run into another problem.. Here is what I have so far. integer CHANNEL = -44; list MENU_MAIN = ["Nothing", "Collect"]; key playerID; default { state_entry() { llListen(CHANNEL, "", NULL_KEY, "" ); if(! ( llGetPermissions() & PERMISSION_DEBIT) ) { llRequestPermissions(llGetOwner(), PERMISSION_DEBIT) ; }
} touch_start(integer num_detected) { string username = llEscapeURL(llDetectedName(0)); string url = "http://mywebsite.com/index.php?name=" + username; string requestid = llHTTPRequest(url,[HTTP_METHOD,"GET"],""); string owe = body; llDialog(llDetectedKey(0), "What is your wish?", MENU_MAIN, CHANNEL); } listen(integer amount, string name, key id, string message)
{ if (message == "Collect") { llSay(0, "You want to collect your pay!"); if (pay > 0) { llGiveMoney(id,owe); } } else { } } }
Basically when someone clicks the collect button it should check a webpage to get the amount. But I know I need http_response(key request_id, integer status, list metadata, string body) in there somewhere.... I'm such a noob.
|
|
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
|
12-23-2006 13:22
From: Danx Daniels And a few minutes later I run into another problem.. Here is what I have so far. integer CHANNEL = -44; list MENU_MAIN = ["Nothing", "Collect"]; key playerID; default { state_entry() { llListen(CHANNEL, "", NULL_KEY, "" ); if(! ( llGetPermissions() & PERMISSION_DEBIT) ) { llRequestPermissions(llGetOwner(), PERMISSION_DEBIT) ; }
} touch_start(integer num_detected) { string username = llEscapeURL(llDetectedName(0)); string url = "http://mywebsite.com/index.php?name=" + username; string requestid = llHTTPRequest(url,[HTTP_METHOD,"GET"],""); string owe = body; llDialog(llDetectedKey(0), "What is your wish?", MENU_MAIN, CHANNEL); } listen(integer amount, string name, key id, string message)
{ if (message == "Collect") { llSay(0, "You want to collect your pay!"); if (pay > 0) { llGiveMoney(id,owe); } } else { } } }
Basically when someone clicks the collect button it should check a webpage to get the amount. But I know I need http_response(key request_id, integer status, list metadata, string body) in there somewhere.... I'm such a noob. Yep you are correct, you need a http_responce event handler in there to 'catch' the reply from the external database. Only once the responce has been received can you get the body (which will be in html!) . So split your code at the llHttpRequest placing the following lines into the http_responce handler, i.e. only trigger the dialog when you get the responce. You may want to also add code to handle not receiving a responce, receiving a NULL responce or just a zero value, in which case there is no point showing a dialog apart from a 'We owe you nothing' message.
|
|
Danx Daniels
Registered User
Join date: 22 Dec 2006
Posts: 99
|
So
12-23-2006 14:58
So how do I fix it? I'm confused about that.
|
|
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
|
12-23-2006 15:21
From: Danx Daniels So how do I fix it? I'm confused about that. Err thought I'd covered that in what I posted?
|
|
Danx Daniels
Registered User
Join date: 22 Dec 2006
Posts: 99
|
Yes
12-23-2006 15:25
You did, but I'm still confused. I'm pretty new to this.
|
|
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
|
12-23-2006 15:48
From: Danx Daniels You did, but I'm still confused. I'm pretty new to this. We all start out that way. Sorry if my post was terse but I have my reasons. End your touch event after the llHttpRequest line move the rest of the touch event code into the http_responce handler I would add a timer incase it stalls but thats just me.
|
|
Danx Daniels
Registered User
Join date: 22 Dec 2006
Posts: 99
|
Hmm
12-23-2006 15:55
I added the touch end after the http request line and I get a syntax error on the next line which is the http response line.
I'm just confused where each line needs to be.
|
|
Danx Daniels
Registered User
Join date: 22 Dec 2006
Posts: 99
|
Here
12-23-2006 16:00
This is my code so far integer CHANNEL = -44; list MENU_MAIN = ["Nothing", "Collect"]; key playerID; default { state_entry() { llListen(CHANNEL, "", NULL_KEY, "" ); if(! ( llGetPermissions() & PERMISSION_DEBIT) ) { llRequestPermissions(llGetOwner(), PERMISSION_DEBIT) ; } } touch_start(integer num_detected) { string username = llEscapeURL(llDetectedName(0)); string url = "http://mywebsite.com/index.php?name=" + username; string requestid = llHTTPRequest(url,[HTTP_METHOD,"GET"],""); } http_response(key request_id, integer status, list metadata, string body) integer pay = (integer)body; { llDialog(llDetectedKey(0), "What is your wish?", MENU_MAIN, CHANNEL); } listen(integer amount, string name, key id, string message) { if (message == "Collect") { llSay(0, "You want to collect your pay!"); llGiveMoney(id,pay); } else { } } }
I get a syntax error at the line integer pay = (integer)body;
|
|
Boss Spectre
Registered User
Join date: 5 Sep 2005
Posts: 229
|
12-23-2006 17:28
From: Danx Daniels I get a syntax error at the line integer pay = (integer)body; try moving that line down inside the brackets wait - Is that a function definition? if so it needs to move above default { }
|
|
Danx Daniels
Registered User
Join date: 22 Dec 2006
Posts: 99
|
Okay
12-23-2006 17:32
I did that and it fixed that problem, now I get an error at llGiveMoney(id,pay);
|
|
Boss Spectre
Registered User
Join date: 5 Sep 2005
Posts: 229
|
12-23-2006 17:34
I think you've run into the line-eater bug in the editor, when you select a line and quickly copy then hit an arrow key is eats what was selected... I hate when that happens.
|
|
Danx Daniels
Registered User
Join date: 22 Dec 2006
Posts: 99
|
Huh
12-23-2006 17:35
I don't understand, how do I fix it?
|
|
Boss Spectre
Registered User
Join date: 5 Sep 2005
Posts: 229
|
12-23-2006 17:46
There were some lines inserted at the wrong place, in the middle of the touch event before the dialog call. I have no idea what it does but this should compile: integer CHANNEL = -44; list MENU_MAIN = ["Nothing", "Collect"]; key playerID; integer pay;
default { state_entry() { llListen(CHANNEL, "", NULL_KEY, "" ); if(! ( llGetPermissions() & PERMISSION_DEBIT) ) { llRequestPermissions(llGetOwner(), PERMISSION_DEBIT) ; } } touch_start(integer num_detected) { string username = llEscapeURL(llDetectedName(0)); string url = "http://mywebsite.com/index.php?name=" + username; string requestid = llHTTPRequest(url,[HTTP_METHOD,"GET"],""); llDialog(llDetectedKey(0), "What is your wish?", MENU_MAIN, CHANNEL); } http_response(key request_id, integer status, list metadata, string body) { pay = (integer)body; } listen(integer amount, string name, key id, string message) { if (message == "Collect") { llSay(0, "You want to collect your pay!"); if (playerID) { if (pay != 0) llGiveMoney(id,pay); else llSay(0, "Your pay is zero!"); } } else { llSay(0, "Thanks for wasting my time!"); } } }
|
|
Danx Daniels
Registered User
Join date: 22 Dec 2006
Posts: 99
|
Well
12-23-2006 17:53
That fixed my problem with the error messages. But now when the object is touched no menu pops up.
|
|
Boss Spectre
Registered User
Join date: 5 Sep 2005
Posts: 229
|
12-23-2006 18:07
Make sure the script is running, if you closed the window with a compile error it will be non-running. Open the script window and check the Running box at the lower left.
|
|
Danx Daniels
Registered User
Join date: 22 Dec 2006
Posts: 99
|
ugh
12-23-2006 18:14
Damn I'm dumb, I didn't notice that. Okay, it works. Where would i need to move the request to the url until after the person clicks collect? I know it should be simple, but I seem to have a lot of problem with where in the script things go.
|
|
Danx Daniels
Registered User
Join date: 22 Dec 2006
Posts: 99
|
Hmm
12-23-2006 20:03
I'm using the version of the script you posted however I'm having some issues still. Of course. When you first click the object is sends a request to the website php script which is setup to calculate how much is owed, print the amount on the screen and mark the user as being paid. However.. If someone is marked as paid before they hit the collect button, it won't pay them. So I need to figure out how to change it so that it doesn't request to the php script until after the collect button is pressed.
Even though it does that it should still send back a 0 and send the message 'Your pay is zero!' but that doesn't happen either. The only thing that happens when someone clicks collect is give the message 'You want to collect your pay!'
My brain hurts. Any help would be appreciated.
|
|
Boss Spectre
Registered User
Join date: 5 Sep 2005
Posts: 229
|
This ought to keep you busy for a while
12-23-2006 23:17
Like I said I did not review it for function... now that I've had time to do that, try this one. integer CHANNEL = -44; list MENU_MAIN = ["Nothing", "Collect"];
list requests; list keys;
default { state_entry() { llListen(CHANNEL, "", NULL_KEY, "" ); if ( !(llGetPermissions() & PERMISSION_DEBIT) ) { llRequestPermissions(llGetOwner(), PERMISSION_DEBIT) ; } } changed(integer change) { if (change & CHANGED_OWNER) { llRequestPermissions(llGetOwner(), PERMISSION_DEBIT) ; } } run_time_permissions(integer perm) { if (perm & PERMISSION_DEBIT) { llOwnerSay("Permissions received, ready to accept requests."); } else { llOwnerSay("Permissions denied, click again if you wish to activate."); state dead; } } touch_start(integer number) { while (--number >= 0) // handle mutiple clicks with a loop { if (!(llGetPermissions() & PERMISSION_DEBIT)) { if (llDetectedKey(number) == llGetOwner()) llRequestPermissions(llGetOwner(), PERMISSION_DEBIT) ; else { llSay(0, "Sorry, unable to pay at the moment"); state dead; } } else { llDialog(llDetectedKey(number), "What is your wish?", MENU_MAIN, CHANNEL); } } } listen(integer amount, string name, key id, string message) { if (message == "Collect") { llSay(0, "You want to collect your pay!"); string url = "http://mywebsite.com/index.php?name=" + llEscapeURL(name); requests += llHTTPRequest(url,[HTTP_METHOD,"GET"],""); keys += id; } else { llSay(0, "Okay, nothing it is, thanks for wasting my time!"); } } http_response(key request_id, integer status, list metadata, string body) { llOwnerSay("request returned " + body + "\""); // debug message integer index = llListFindList(requests, [request_id]); if (index >= 0) // id matches one we are expecting { integer pay = (integer)body; // store what was returned key playerID = llList2Key(keys, index); if (playerID) // valid key { if (pay != 0) { llSay(0, "paying L$" + (string)pay + " to " + llKey2Name(playerID)); // llGiveMoney(playerID,pay); } else { llSay(0, "Your pay is zero!"); } } else { llSay(0, "Invalid player ID \"" + (string)playerID + "\""); } // remove from lists requests = llDeleteSubList(requests, index, index); keys = llDeleteSubList(keys, index, index); } } }
state dead { touch_start(integer number) { while (--number >= 0) // handle mutiple clicks with a loop { if (llDetectedKey(number) == llGetOwner()) state default; else llSay(0, "Sorry, inactive at the moment."); } } } Scripts are never simple when money is involved 
|
|
Danx Daniels
Registered User
Join date: 22 Dec 2006
Posts: 99
|
WOw
12-23-2006 23:28
Your a damn genius! Should I send my wife or first born? Well, since I have no kids you'll have to take the woman. Okay, well I've only tested it a little and it works exactly as I want. But I'll have to test it a bit more to make sure there are no unforseen problems. I'll have to give you a commission once I get everything up and running.  Thanks again for the help
|
|
Boss Spectre
Registered User
Join date: 5 Sep 2005
Posts: 229
|
12-24-2006 22:00
Oh dang I forgot to insert the line to pay me a percentage of everyone's salary.
Merry Christmas I'm glad it helped.
|