Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Bizare behavior from simple script

Samantha Fuller
Registered User
Join date: 8 Sep 2006
Posts: 15
09-21-2006 21:39
I can't for the life of me figure out why this script dosent work like it shoud.
whisper results:
on compile - initalizing counter
first touch - nothing
each susequent touche - closing, opening, opened
-door also moved in local +x direction each time
CODE

//**********************************************
//Title: Barn door left
//Author: Samantha Fuller 9/18/06
// Version 1
//**********************************************

string CLOSE;
string OPEN;
integer num_knocks;
integer shut = TRUE;
default
{
state_entry()
{
num_knocks = 0; // initalize counter
llWhisper(0, "initalizing counter");
}

touch_start(integer num_detected)
{
++ num_knocks;
if(num_knocks = 1)
{
//other door is the same except door movement direction
llMessageLinked(LINK_SET, 0, "CLOSE", NULL_KEY);
llWhisper(0, "Closeing");
}

if(num_knocks = 2)
{
llMessageLinked(LINK_SET, 0, "OPEN", NULL_KEY);
llWhisper(0, "Opening");
}

if(num_knocks >=3 )
{
llWhisper(0, "reset to default");
state reset_to_default;
}
}

link_message(integer sender_num, integer num, string str, key id)
{
if(str == "CLOSE")
{
if(shut = FALSE)
{
//llSetRot(llGetLocalRot() + <1,0,0,0>);
llSetPos(llGetLocalPos() + <2,0,0>);
llWhisper(0, "Closed");
//llMessageLinked(LINK_ALL_OTHERS, 0, "closed", NULL_KEY);
shut = TRUE;
}
}
if(str == "OPEN")
{
if(shut = TRUE)
{
//llSetRot(llGetLocalRot() + <1,0,0,0>);
llSetPos(llGetLocalPos() + <-2,0,0>);
llWhisper(0, "Opened");
//llMessageLinked(LINK_ALL_OTHERS, 0, "open", NULL_KEY);
shut = FALSE;
} //close verification toggel
} //close str mesage
} //close link_mesage
} //close defualt state

state reset_to_default
{
state_entry()
{
//this state exist because default canot be called from itself
llWhisper(0, "default");
state default;
}
}
Lazink Maeterlinck
Registered User
Join date: 8 Nov 2005
Posts: 332
09-21-2006 21:56
in your if statements you have = not ==, so your assigning that number to whatever it is, and that returns true, you want to change those ='s to ==.

CODE


//**********************************************
//Title: Barn door left
//Author: Samantha Fuller 9/18/06
// Version 1
//**********************************************

string CLOSE;
string OPEN;
integer num_knocks;
integer shut = TRUE;
default
{
state_entry()
{
num_knocks = 0; // initalize counter
llWhisper(0, "initalizing counter");
}

touch_start(integer num_detected)
{
++ num_knocks;
if(num_knocks == 1)
{
//other door is the same except door movement direction
llMessageLinked(LINK_SET, 0, "CLOSE", NULL_KEY);
llWhisper(0, "Closeing");
}

if(num_knocks == 2)
{
llMessageLinked(LINK_SET, 0, "OPEN", NULL_KEY);
llWhisper(0, "Opening");
}

if(num_knocks >=3 )
{
llWhisper(0, "reset to default");
state reset_to_default;
}
}

link_message(integer sender_num, integer num, string str, key id)
{
if(str == "CLOSE")
{
if(shut == FALSE)
{
//llSetRot(llGetLocalRot() + <1,0,0,0>);
llSetPos(llGetLocalPos() + <2,0,0>);
llWhisper(0, "Closed");
//llMessageLinked(LINK_ALL_OTHERS, 0, "closed", NULL_KEY);
shut = TRUE;
}
}
if(str == "OPEN")
{
if(shut == TRUE)
{
//llSetRot(llGetLocalRot() + <1,0,0,0>);
llSetPos(llGetLocalPos() + <-2,0,0>);
llWhisper(0, "Opened");
//llMessageLinked(LINK_ALL_OTHERS, 0, "open", NULL_KEY);
shut = FALSE;
} //close verification toggel
} //close str mesage
} //close link_mesage
} //close defualt state

state reset_to_default
{
state_entry()
{
//this state exist because default canot be called from itself
llWhisper(0, "default");
state default;
}
}
Samantha Fuller
Registered User
Join date: 8 Sep 2006
Posts: 15
Thank you
09-22-2006 00:26
Thank you very much.

Though i had to also add a line to the second if conditional, reseting the counter to get the script to behave like i wanted.

It is hard for pepole new to programing to think like a computer.
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
09-22-2006 02:32
From: Samantha Fuller
Thank you very much.

Though i had to also add a line to the second if conditional, reseting the counter to get the script to behave like i wanted.

It is hard for pepole new to programing to think like a computer.



Not as hard as it is for a computer to think like a human. :)

Mixing up the equality operator (==) and assignment operator (=) is probably the most common bug. A way to help protect against this is to always put the constant on the LHS, i.e.

instead of
CODE
if(value == 2){ dosomething; }


use
CODE
if(2 == value)){ dosomething; }


That way if you do get it wrong the compiler will tell you. of course if your checking 2 variables for equality you're on your own again!