Showing posts with label llRequestPermissions. Show all posts
Showing posts with label llRequestPermissions. Show all posts

Thursday, August 21, 2008

Second Life Physics Scripting - Pinball #26 - The First Player

I put in some logging to see if anyone was playing the actual game. I had my first player (Grimley Graves) and asked him if the game was actually working. He owns a haunted house down the street which is how he found the game. Sure enough, the game didn't work at all. He offered to help me test it and I found the problem.

The problem was in the keyboard code from post #12. This is what I had.


llRequestPermissions(llGetOwner(), PERMISSION_TAKE_CONTROLS);


It turns out that the first parameter is the person who's keys you want to take over. Sure enough since I'm the owner and was neaby when he touched the table, I received the dialog asking if I wanted to play. Oops.

This is the correct code.


llRequestPermissions(llDetectedKey(0), PERMISSION_TAKE_CONTROLS);


The llDetectedKey(0) is the key for the first avatar that touched the table. Once I made this change everything worked great. I went back and changed post #12 to reflect this difference so someone doesn't have this same problem later.

Monday, July 14, 2008

Second Life Physics Scripting - Pinball #12 - Keyboard Control

I was finally able to trap the keyboard and I wanted to post a code snipet because it should show it in a fairly simple way.
default
{
state_entry()
{
}

// this is called by llRequestPermission
run_time_permissions(integer perm)
{
// permissions dialog answered
if (perm & PERMISSION_TAKE_CONTROLS)
{
// we got a yes
// take up and down controls
llTakeControls(CONTROL_ROT_LEFT
CONTROL_ROT_RIGHT
CONTROL_UP
CONTROL_DOWN,
TRUE, FALSE);
}
}

touch_start(integer total_number)
{
llSay(0, "Would you like to play? I'll need to take over your keyboard.");
llSay(0, "This doesn't work yet, it's still under construction.");

integer perm= llGetPermissions();

if (!perm&PERMISSION_TAKE_CONTROLS)
{
// get permission to take controls
// this was changed after the blog entry
// it needs to be called with detectedKey. During debugging
// you might still want to use llGetOwner to avoid others interupting.
llRequestPermissions(llDetectedKey(0), PERMISSION_TAKE_CONTROLS);
//llRequestPermissions(llGetOwner(), PERMISSION_TAKE_CONTROLS);
}
else
{
llSay(0,"We have permission to take control...trying");
// this was changed after the blog entry
// it needs to be called with detectedKey. During debugging
// you might still want to use llGetOwner to avoid others interupting.
llRequestPermissions(llDetectedKey(0), PERMISSION_TAKE_CONTROLS);
//llRequestPermissions(llGetOwner(), PERMISSION_TAKE_CONTROLS);
// the sl wiki says that you should always request permission
//llTakeControls(CONTROL_LEFT
// CONTROL_RIGHT
// CONTROL_UP CONTROL_DOWN,
// TRUE, TRUE);
}
}
control(key id, integer held, integer change)
{
llSay(0, "control id="+(string)id);
llSay(0, " held="+(string)held+" change="+(string)change);
}
}
These are the two wiki entries I used to get this done.
http://wiki.secondlife.com/wiki/LlTakeControls
http://www.lslwiki.net/lslwiki/wakka.php?wakka=llTakeControls

One thing I don't like is that it only seams like you can get information on keys that are already mapped to movement. In this case a,w,s,d,e,c,arrow keys and page up/down. This seems very limiting, but I think I can make it work. Seems like an oversite that would have been easy to allow for early on in the development process and I have trouble understanding any reason for this other than a lack of vision in regards to in world controls.