Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Sitting Script problems

Jackal Koskinen
Registered User
Join date: 29 Jan 2009
Posts: 8
06-03-2009 12:02
Hi everyone,

Lately I've been practicing the Linden Scripting Language, and have run into a few problems.


string variable = "";

default
{
state_entry()
{
llRequestAgentData(llGetCreator(), DATA_NAME);
llSitTarget(<0,0,1>, ZERO_ROTATION);
}

dataserver(key rueryid, string data) {
variable = data;
}

changed(integer change) {
if(llAvatarOnSitTarget() != NULL_KEY) {
else {
if(llKey2Name(llAvatarOnSitTarget()) == variable) {
llSay(0, "Hello, Jackal. Welcome to your chair.";);}
else {
llSay(0,"Sorry, this chair belongs to Jackal Koskinen!";);
llSleep(0.5);
llUnSit(llAvatarOnSitTarget());
}
}
}
}


There was an example on the wiki that made it unsit everyone. I decided to practice a bit and made the first thing that came to my mind. (A "private" chair). What happens is when I sit down, it seems to work until the first If statement. It seems to stop after that. (I added random llSay's between the code to see what was working and what wasn't.) Then after I Stand up, it re-runs the script, and actually passes the first If Statement. But I'm already off the target. I've been playing with it for a few hours, learning about Key2Name and everything in the process but I'm starting to get a bit frustrating. Every time I solve a problem myself, I run into another. Or maybe point me to a certain function I might wanna look up myself it'd be a lot of help. Thanks.
Pale Spectre
Registered User
Join date: 2 Sep 2005
Posts: 586
06-03-2009 12:41
As it stands your script doesn't compile (an unmatched braces thing).

Not withstanding that this might get you started:

CODE

default
{

state_entry()
{
llSitTarget(<0,0,1>, ZERO_ROTATION);
}

changed(integer change)
{
if(change & CHANGED_LINK)
{
if(llAvatarOnSitTarget() != NULL_KEY)
{
if(llAvatarOnSitTarget() == llGetCreator())
{
llSay(0, "Hello, Jackal. Welcome to your chair.");
}
else
{
llSay(0,"Sorry, this chair belongs to [was created by] Jackal Koskinen!");
llSleep(0.5);
llUnSit(llAvatarOnSitTarget());
}
}
}
}
}


Notice that the changed event caters for things other than just someone sitting (linking) to an object.
_____________________
Escort DeFarge
Together
Join date: 18 Nov 2004
Posts: 681
06-03-2009 12:55
Hi Jackal,

Here's one that should work. Have a good read and compare to what you have and much light should dawn.

Note that only the chair creator will be able to sit -- not the current owner (not sure how useful that is).

Making it so only the owner can sit would be simpler (you wouldn't need the dataserver call) but this version shows how to do what you appeared to want to do.

regs,
/esc

CODE


vector SIT_POS = <0.0, 0.0, 1.0>;
rotation SIT_ROT = ZERO_ROTATION;

key query;
string FIRST_NAME;
string LAST_NAME;
//
default {
state_entry() {
llSitTarget(SIT_POS, SIT_ROT);
query = lRequestAgentData(llGetCreator(), DATA_NAME);
}

dataserver(key id, string info) {
if (id == query) {
query = NULL_KEY;
list parts = llParseString2List(info, [" "], []);
FIRST_NAME = llList2String(parts, 0);
LAST_NAME = llList2String(parts, 1);
CREATOR_NAME = info;
}
}

changed(integer change) {
if (change & CHANGED_LINK) {
llSleep(0.02);
key avatar = llAvatarOnSitTarget();
if (avatar != NULL_KEY) {
if (avatar == llGetCreator()) {
llInstantMessage(avatar, "Hello, " + FIRST_NAME + ", welcome to your chair!");
} else {
llInstantMessage(avatar, "Sorry, " + llKey2Name(avatar)
+ ", this chair belongs to " + llDumpList2String([FIRST_NAME, LAST_NAME], " "));
llUnSit(avatar);
}
}
}
}
}


_____________________
http://slurl.com/secondlife/Together
Jackal Koskinen
Registered User
Join date: 29 Jan 2009
Posts: 8
06-03-2009 14:30
Thanks Escort and Pale. Yeah, getting the owner of the object probably would've been an easier path for me. But trail and error is the best way. Thanks so much again. I'm looking at both and reading up on what I don't understand.