Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Controling functions in multiple states.

Lucius Obviate
Evil Incarnate
Join date: 5 Dec 2006
Posts: 15
02-15-2007 00:23
Basically this is what I need to do is based on a condition in the control state using CONTROL_FWD, CONTROL_LEFT & CONTROL_RIGHT tell it to execute a specific llSay function in the sensor state.

CODE


control(key id, integer held, integer change)
{

if ((held & CONTROL_ML_LBUTTON) && (held & CONTROL_FWD) && (change & CONTROL_FWD))
{
llSensor("",NULL_KEY, AGENT,3, PI_BY_TWO*0.5);
}

else if ((held & CONTROL_ML_LBUTTON) && (~held & CONTROL_LEFT) && (change & CONTROL_LEFT))
{
llSensor("",NULL_KEY, AGENT,3, PI_BY_TWO*0.5);
}
else if ((held & CONTROL_ML_LBUTTON) && (~held & CONTROL_RIGHT) && (change & CONTROL_RIGHT))
{
llSensor("",NULL_KEY, AGENT,3, PI_BY_TWO*0.5);
}
}

sensor(integer sensed)
{
{
if (CONTROL_FWD is being used)
llSay(0, "say this stuff")
}

{
else if (CONTROL_LEFT is being used)
llSay(0, "say this stuff")
}

{
else if (CONTROL_RIGHT is being used)
llSay(0, "say this stuff")
}
)


Hopefully thats clear enough if it isnt let me know and I will endevor to explain it better.
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
02-15-2007 01:14
You should be able to use a global variable to store the information

CODE

integer keysHeld;
integer keysChanged;

default
{
control(key id, integer held, integer change)
{
keysHeld = held;
keysChanged = change;

if ((held & CONTROL_ML_LBUTTON) && (held & CONTROL_FWD) && (change & CONTROL_FWD))
{
llSensor("",NULL_KEY, AGENT,3, PI_BY_TWO*0.5);
}

else if ((held & CONTROL_ML_LBUTTON) && (~held & CONTROL_LEFT) && (change & CONTROL_LEFT))
{
llSensor("",NULL_KEY, AGENT,3, PI_BY_TWO*0.5);
}
else if ((held & CONTROL_ML_LBUTTON) && (~held & CONTROL_RIGHT) && (change & CONTROL_RIGHT))
{
llSensor("",NULL_KEY, AGENT,3, PI_BY_TWO*0.5);
}
}

sensor(integer sensed)
{
if (CONTROL_FWD & keysHeld)
{
llSay(0, "say this stuff");
}
else if (CONTROL_LEFT & keysHeld)
{
llSay(0, "say this stuff");
}
else if (CONTROL_RIGHT & keysHeld)
{
llSay(0, "say this stuff");
}
}
}
Lucius Obviate
Evil Incarnate
Join date: 5 Dec 2006
Posts: 15
02-15-2007 02:58
For some reason the second conditions in the sensor state arent functioning. IE it will work with CONTROL_FWD but when using CONTROL_RIGHT & CONTROL_LEFT nothing happens.


***edit***

I love it when ~ causes half my script not to work. =\
Problem solved and the script is working perfectly, thank you for your help. :)
Stephen Zenith
Registered User
Join date: 15 May 2006
Posts: 1,029
02-15-2007 03:36
Just to clarify, sensor is an event, not a state. The only state you have in your code id the default state.
Lucius Obviate
Evil Incarnate
Join date: 5 Dec 2006
Posts: 15
02-15-2007 06:04
Thanks for the clarification, there is nothing worse than using the wrong terminology and noone correcting you on it.