llRequestPermissions and state changes
|
Tadao Nordenskiold
Registered User
Join date: 9 May 2009
Posts: 37
|
11-05-2009 10:54
Is there any limit on hom many state changes the permissions would hold through?
Right now, I have 4 states in my script, and 3 untill the script triggers the second script that holds the money event.
States:
Default, check_perm, Request_data (I'm requesting some data with HTTPRequest that is needed in another state), (Inactive) In case permissions havn't been granted within a certain amount of time, Active, Finnished.
At the end of the Active state, it first sends an linked message to trigger the script holding the money event, and then it goes to state finnished to wait for an linked message that tells it to move back to state default.
But when I come to the end of state active, the perm bits is 0, when it should have been 2. What could cause the scrip to loose the permissions? And how could I work it out not to?
Variable (string) perm is defined in globals and set in run_time_permissions event in the check_perm state.
|
Tadao Nordenskiold
Registered User
Join date: 9 May 2009
Posts: 37
|
11-05-2009 12:36
I tried to modify the script a bit to figure out where the permisions is lost, and it still puzzles me....
The states:
Default, check_perm, Request_data (I'm requesting some data with HTTPRequest that is needed in another state) (content moved to check_perm, this state is not used now), (Inactive) In case permissions havn't been granted within a certain amount of time, Active, Finnished (Is currently not beeing used)
At the beginning and end of each state, I am using llSay to give me the permission bits. As soon as permissions is set, I get 2 as an answer.
At the end of check_perms the same, 2. But in the state_entry of state active, the permissions is lost and gives me 0.
Anyone have any ideas? Would you need to see my script?
|
Meade Paravane
Hedgehog
Join date: 21 Nov 2006
Posts: 4,845
|
11-05-2009 12:37
From: Tadao Nordenskiold Would you need to see my script? Please.
_____________________
Tired of shouting clubs and lucky chairs? Vote for llParcelSay!!! - Go here: http://jira.secondlife.com/browse/SVC-1224- If you see "if you were logged in.." on the left, click it and log in - Click the "Vote for it" link on the left
|
Tadao Nordenskiold
Registered User
Join date: 9 May 2009
Posts: 37
|
11-05-2009 12:41
key toucher = NULL_KEY; string planrequest; string server = "http://my-server/"; integer x; integer i = 0; list datalist; integer length; integer touched; integer handle; integer perm;
string plan; integer price; integer listeners; integer bitrate; integer upload; string linked_message; integer selection_set; list Linkselection_list; // May be removed string trigger; // May be removed
string online; key Tadao = "05c9fe42-8d89-401d-a9a5-2d82af58e16f";
default { state_entry() { llWhisper(0, "Requestion data, please wait"); llSetLinkTexture(6, "Gaia_Streams_Main", 5); llRequestPermissions(llGetOwner(),PERMISSION_DEBIT); state check_perm; } }
state check_perm { run_time_permissions(integer perm) { perm = llGetPermissions(); if ( perm & PERMISSION_DEBIT ) { llWhisper(0, "Permissions granted, data fetched, lets go"); llSetLinkPrimitiveParams(4, [ PRIM_COLOR, ALL_SIDES, <0.0, 1.0, 0.0>, 1.0, PRIM_FULLBRIGHT, ALL_SIDES, TRUE, PRIM_GLOW, ALL_SIDES, 0.1 ]); planrequest = llHTTPRequest(server + "custom/get_menu_items.php", [ HTTP_METHOD, "GET"], ""); llSay(0, "perm bits after planrequest: "+(string)perm); } else { vector position = llGetPos(); float X = llRound(position.x); float Y = llRound(position.y); float Z = llRound(position.z);
llWhisper(0, "Denied, will try again in 15 minutes!"); llInstantMessage(Tadao, "I am the vending machine located at: " +"http://slurl.com/secondlife/" +llGetRegionName() +"/" +(string)X +"/" +(string)Y +"/" +(string)Z +"/ \n" +"For some reason you have denied me debit rights, which I need to fully function!/n" +"I will ask you for permissions again each 15 minutes untill you either grant them or completely shut me down!"); llSetLinkPrimitiveParams(4, [ PRIM_COLOR, ALL_SIDES, <1.0, 0.0, 0.0>, 1.0, PRIM_FULLBRIGHT, ALL_SIDES, TRUE, PRIM_GLOW, ALL_SIDES, 0.1]); state inactive; } llSay(0, "perm bits before http_response: "+(string)perm); } http_response(key request_id, integer status, list metadata, string body) { if (request_id == planrequest) { datalist = llParseString2List(body, ["#"], []); length = llGetListLength(datalist); // state active; } // state request_data; llSay(0, "perm bits before leaving state check_perms: "+(string)perm); state active;
} }
state request_data { http_response(key request_id, integer status, list metadata, string body) { if (request_id == planrequest) { datalist = llParseString2List(body, ["#"], []); length = llGetListLength(datalist); state active; } } }
state inactive { state_entry() { llSetTimerEvent(900.0); llOwnerSay("Entering state inactive"); } timer() { llOwnerSay("leaving state inactive to check perms!"); state default; } }
state active { state_entry() { llSay(0, "State active, perm bits set to: "+(string)perm); handle = llListen(40, "", "", ""); } touch_start(integer num_detected) { if (touched) { if ( toucher != llDetectedKey(0)) { llInstantMessage(llDetectedKey(0), "Sorry, I'm busy with another customer. Please try again in a few moments."); return; } } else { touched = TRUE; llSetTimerEvent(180); toucher = llDetectedKey(0); llWhisper(0, "Vendor is locked to customer " +llKey2Name(toucher) +" for 3 minutes."); if (selection_set == 0) { selection_set = 1; llMessageLinked(2, 0, "selection", NULL_KEY); llSetLinkTexture(2, "Select", 5); llOwnerSay("selection_set=" +(string)selection_set); } } } touch_end(integer total_number) { if ( toucher == llDetectedKey(0)) { if (datalist != []) { if ( i <= length ) { if ( i == length ) { i = 0; } // llOwnerSay("row: " +(string)i +"\n"+llList2String(datalist,i)); // Set variables list current_string = llParseString2List(llList2String(datalist,i), ["|"], []); plan = llList2String(current_string,0); price = llList2Integer(current_string,1); listeners = llList2Integer(current_string,2); bitrate = llList2Integer(current_string,3); upload = llList2Integer(current_string,4); // llOwnerSay("\nSelected plan: " +plan // +"\nPrice: L$" +(string)price // +"\nMax listeners: " +(string)listeners // +"\nMax bitrate: " +(string)bitrate // +"\nUpload limit: " +(string)upload); linked_message = "selected_plan|" +plan +"|" +(string)price +"|" +(string)listeners +"|" +(string)bitrate +"|" +(string)upload +"|" +(string)toucher; llMessageLinked(2, 0, linked_message, NULL_KEY); // llDialog(toucher, "Click on \"Select\" in order to choose this plan!", [plan], 35); llSetLinkTexture(6, plan, 5); // llOwnerSay(plan); // llOwnerSay(linked_message); i++; llOwnerSay((string)i); } } else { llOwnerSay("List empty"); } } } link_message( integer sender_num, integer num, string received_msg, key id ) {
if ( received_msg == "ConFirm_MsG" ) { llSay(0, "perm bits set to: "+(string)perm); // state finnished; } } }
state finnished { link_message( integer sender_num, integer num, string done_trigger, key id ) { if ( done_trigger == "Customer_Done" ) { touched = FALSE; toucher = NULL_KEY; selection_set = 0; llMessageLinked(2, 0, "Vendor_Slide", NULL_KEY); llWhisper(0, "Unlocked, next customer please."); state active; } } }
There are a lot of unnessecary comments and for sure a few bugs. I'd be happy for any constructive comments you could give me...
|
Meade Paravane
Hedgehog
Join date: 21 Nov 2006
Posts: 4,845
|
11-05-2009 12:52
I think any state change will always clear the event queue so, in general, you should avoid doing stuff like this..
llRequestPermissions(llGetOwner(),PERMISSION_DEBIT ); state check_perm;
...though it's probably not likely to bite you in this case, if the sim decides to auto-grant premissions, it might post the event to call run_time_permissions before the state change completes - you'd lose the event that way.
(edit: err.. actually you do change back to the default state so it might be granting this automatically)
You've got global variable called "perm" defined. When this code runs...
run_time_permissions(integer perm) { perm = llGetPermissions();
...you're reassigning the local variable called 'perm' to the permissions mask, not the global variable. Try changing it to be 'integer mask' or something instead.
_____________________
Tired of shouting clubs and lucky chairs? Vote for llParcelSay!!! - Go here: http://jira.secondlife.com/browse/SVC-1224- If you see "if you were logged in.." on the left, click it and log in - Click the "Vote for it" link on the left
|
Tadao Nordenskiold
Registered User
Join date: 9 May 2009
Posts: 37
|
11-05-2009 13:04
Well, when it comes to state changes, I found something in the wiki http://wiki.secondlife.com/wiki/LlRequestPermissionsIt's saying that the set permission persists through state changes, so that should not be a problem. When it comes to change back to default state, yes, I do change back to default state if the current state is state inactive. After 900 seconds in this state, I go back to default to try grant permissions again. The only reason to why the variable "perm" is set in the globals, is to be able to follow it through the state changes with llSay. If I don't define it in the globals, I get "Name not defined within scope" errors. (but ofcourse, only when using llSay in other states). I don't understand what you mean. Correct me if I am wrong, but when I set integer perm; as global, and then using it in liek I am doing run_time_permissions(integer perm) { perm = llGetPermissions();
Don't I assign the the llGetPermissions TO the variable "perm"? If I understand you correct, you are suggesting that I am reassigning llGetPermissions to what ever "perms" is holding, which, in this case, is NULL.
|
Meade Paravane
Hedgehog
Join date: 21 Nov 2006
Posts: 4,845
|
11-05-2009 13:13
This line...
run_time_permissions(integer perm)
...declares another variable named 'perm'. When you use that variable name within that function, you're only using the local variable.
So... This line...
perm = llGetPermissions();
...is just updating the local variable.
Use this instead:
run_time_permissions(integer mask)
edit: and the stuff I was saying about state changes/events was just general good-practice stuff. If you do things like you have them now, there's a chance that the run_time_permissions event won't ever get called back, even if the user granted permissions.
_____________________
Tired of shouting clubs and lucky chairs? Vote for llParcelSay!!! - Go here: http://jira.secondlife.com/browse/SVC-1224- If you see "if you were logged in.." on the left, click it and log in - Click the "Vote for it" link on the left
|
Tadao Nordenskiold
Registered User
Join date: 9 May 2009
Posts: 37
|
11-05-2009 13:44
Ahh, thank you.  THe user who needs to grant permissions is me though, as it is my vending mashine. 
|
Meade Paravane
Hedgehog
Join date: 21 Nov 2006
Posts: 4,845
|
11-05-2009 14:46
From: Tadao Nordenskiold Ahh, thank you.  Did the problem go away?? From: Tadao Nordenskiold THe user who needs to grant permissions is me though, as it is my vending mashine.  Yep. You can only request debit perms from the owner of the object. My only point was that when you end up going back to state default, the debit permission might not pop up again - if LL messes with script timings (and they are talking about this right now) you could end up getting an incoming run_time_permissions callback event while you're in the process of changing state. If that happens, you don't get the event.
_____________________
Tired of shouting clubs and lucky chairs? Vote for llParcelSay!!! - Go here: http://jira.secondlife.com/browse/SVC-1224- If you see "if you were logged in.." on the left, click it and log in - Click the "Vote for it" link on the left
|
Tadao Nordenskiold
Registered User
Join date: 9 May 2009
Posts: 37
|
11-05-2009 14:54
I am just about to test it, I had to be elsewhere for a while and couldn't try. Hmm, that sounds like a pretty bad thing to be frank.  Any suggestions of how to get away from that problem?
|
Tadao Nordenskiold
Registered User
Join date: 9 May 2009
Posts: 37
|
11-05-2009 15:13
Hmm.. it cleared the proble for this script.. but as soon as the next script took over, it seems that the permission is lost again.
I wonder if there has been some kind of change so that the permissions needs to be set in the script where whe money event is. Or could there be anything else that is wrong?
|
Sindy Tsure
Will script for shoes
Join date: 18 Sep 2006
Posts: 4,103
|
11-05-2009 16:20
From: Tadao Nordenskiold I am just about to test it, I had to be elsewhere for a while and couldn't try. Hmm, that sounds like a pretty bad thing to be frank.  Any suggestions of how to get away from that problem? Around the losing events on state change stuff? Not really - it's just something you have to watch out for in your code.. Right now, you have this: llRequestPermissions(llGetOwner(),PERMISSION_DEBIT ); state check_perm;
Instead of that, do the state change then, in state_entry for the check_perm state, do the llRequestPermissions. I think that's all Meade was trying to say.
_____________________
Sick of sims locking up every time somebody TPs in? Vote for SVC-3895!!! - Go here: https://jira.secondlife.com/browse/SVC-3895- If you see "if you were logged in.." on the left, click it and log in - Click the "Vote for it" link on the left
|
Tadao Nordenskiold
Registered User
Join date: 9 May 2009
Posts: 37
|
11-05-2009 16:38
Hehe, was a little bit to late. I got a bit pissed, and thought of another way to work around the problem.  I moved the permissions states to the script that handles the money event instead. I figured it would work as good since all of the scripts anyway are going through the state_entry in default as soon as the object rezzes.  Now I only have one small question that is unrelated to the orignal problem. Timers... As stated on the wiki, only one timer can be active at a time. And timers do survice state changes. As you can see in the script, I have one timer in the inactive state, and yet another one (allthough not activated) in the active state. How do I do so that these timers does not interfere with each other? Is it just as simple as adding a timer event in the active state too? Or do I need to do anything with the timer event I got in the inactive state aswell?
|