Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Scope Variable issue please help!

Diego Pannotia
Laronzo Fitzgerald
Join date: 14 Nov 2006
Posts: 37
02-10-2007 07:27
Just started with LSL I'm afraid so forgive any easy questions +D

The script below works (open and close a door via an external server)

What I'd like to do is set a variable like "integer Touched" to say "1" when the door is touched i.e.:

CODE

touch_start(integer N)
{
integer Touched = 1;


and then change this:

CODE

if(sval == "on")
{
llSay(0, "Door Opened!");
state open;
}


to something like this:

CODE

if(sval == "on")
{
if(touched =="1"){ llSay(0, "Door Opened!");
} else
state open;
}


I don't know how to get the variable in scope however...

The full code atm:

CODE

vector OpenRot = <0.00, 0.00, 192.25>;

vector ClosedRot = <0.00, 0.00, 281.25>;

key gChannel;

DEBUG(list out)
{
llSay(0, llList2CSV(out));
}

default
{
state_entry()
{
llOpenRemoteDataChannel();
}

remote_data(integer type, key channel, key message_id, string sender, integer ival, string sval)
{
if (type == REMOTE_DATA_CHANNEL)
{
gChannel = channel;
llSay(0, "Channel: " + (string)channel +"");
state closed;
} else DEBUG(["Unexpected event type", type, channel, message_id, sender, ival, sval]);
}
}

state closed
{
touch_start(integer N)
{
llHTTPRequest("http://...msg=door%20on",[HTTP_METHOD,"GET"],"");
}

state_entry()
{
llSetRot(llEuler2Rot(ClosedRot * DEG_TO_RAD));
}

remote_data(integer type, key channel, key message_id, string sender, integer ival, string sval)
{
if (type == REMOTE_DATA_REQUEST)
{
// DEBUG(["Received", ival, sval]);
string stringPortionOfReply = "Default Reply";
integer intPortionOfReply = 0;

if(sval == "on")
{
llSay(0, "Door Opened!");
state open;
}

llRemoteDataReply(channel, message_id, stringPortionOfReply, intPortionOfReply);

} else DEBUG(["Unexpected event type:", type, channel, message_id, sender, ival, sval]);
}

}


state open
{
touch_start(integer N)
{
llHTTPRequest("http://......msg=door%20off",[HTTP_METHOD,"GET"],"");
}

state_entry()
{
llSetRot(llEuler2Rot(OpenRot * DEG_TO_RAD));
}

remote_data(integer type, key channel, key message_id, string sender, integer ival, string sval)
{
if (type == REMOTE_DATA_REQUEST)
{
// DEBUG(["Received", ival, sval]);
string stringPortionOfReply = "Default Reply";
integer intPortionOfReply = 0;

if(sval == "off")
{
llSay(0, "Door Closed!");
state closed;
}

llRemoteDataReply(channel, message_id, stringPortionOfReply, intPortionOfReply);

} else DEBUG(["Unexpected event type:", type, channel, message_id, sender, ival, sval]);
}

}
Baron Hauptmann
Just Designs / Scripter
Join date: 29 Oct 2005
Posts: 358
02-10-2007 08:00
To declare a global variable, just declare it outside any state. ie, where you have

CODE

key gChannel;


add

CODE

key gChannel;
integer touched;


If you want it to begin with a particular value, try

CODE

key gChannel;
integer touched = FALSE;


Then, the value for touched will persist across states.

Hope that helps.
Baron
Diego Pannotia
Laronzo Fitzgerald
Join date: 14 Nov 2006
Posts: 37
Cheers!
02-10-2007 08:13
Ah fantastic! So it does =D
Lee Ponzu
What Would Steve Do?
Join date: 28 Jun 2006
Posts: 1,770
02-10-2007 08:20
Just a trivial side comment, but your example used Touched in one place and touched in another. Case matters. Be careful.