I am simply trying to use llSensor to determine if the Owner is within range; if not then the name of the nearest Agent and failing that the key of the object itself. All this is working fine within the sensor() event itself.
The problem I'm *seemingly* having, or at least what I originally believed I am having, is making the key so determined by the sensor() event avaliable to other functions outside of the event itself. However, it could be that I'm missing a fundemental in the process-flow of scripts in LSL.
The follow code demonstrates the problem (and is a much simplified version of the code I am working on.)
~ On Touch, FuctionOne() is called
~ FunctionOne calls FunctionTwo()
~ FunctionTwo() makes the llSensor() call and initiates the sensor() event
~ The sensor() event both successfully populates TempTarget & assigns this value to GlobalTarget
~ However, when FunctionTwo() comes the use the value in GlobalTarget after the llSensor() call, it is NOT the same value as was successfully populated in the sensor() event
//*************************************************************************
key GlobalTarget;
integer DoSensor = TRUE;
FunctionTwo()
{
if (DoSensor == TRUE)
{
llSay(0, "DEBUG POINT 2 " + llKey2Name(GlobalTarget));
//llSensor() call
llSensor("", NULL_KEY, AGENT, 5, PI);
llSay(0, "DEBUG POINT 7: GlobalTarget is " + llKey2Name(GlobalTarget));
//use GlobalTarget that was correctly populated in the sensor() event
if (GlobalTarget == llGetOwner())
{
llSay(0, "GlobalTarget has been CORRECTLY populated"
;}
else
{
llSay(0, "GlobalTarget has been INCORRECTLY populated"
;}
}
}
FunctionOne()
{
llSay(0, "DEBUG POINT 1: GlobalTarget is " + llKey2Name(GlobalTarget));
FunctionTwo();
llSay(0, "DEBUG POINT 8: GlobalTarget is " + llKey2Name(GlobalTarget));
}
//************************************
default
{
state_entry()
{
llSay("Hello, Avatar"
;}
//************************************
touch_start(integer touch_number)
{
GlobalTarget = llGetKey();
FunctionOne();
}
//************************************
sensor(integer sensor_number)
{
key TempTarget;
integer i;
for (i = 0; i < sensor_number; i++)
{
llSay(0, "DEBUG POINT 3 " + llKey2Name(llDetectedKey(i)));
if (llDetectedKey(i) == llGetOwner())
{
llSay(0,"The Owner is " + llKey2Name(llDetectedKey(i)));
TempTarget = llDetectedKey(i);
llSay(0, "DEBUG POINT 4: TempTarget is " + llKey2Name(TempTarget));
}
}
llSay(0, "DEBUG POINT 5: TempTarget is " + llKey2Name(TempTarget));
GlobalTarget = TempTarget;
llSay(0, "DEBUG POINT 6: GlobalTarget is " + llKey2Name(GlobalTarget));
}
}
//*************************************************************************
The DEBUG POINTS in the above code show my (obviously erroneous) *expectation* for process-flow:
DEBUG POINT 1
DEBUG POINT 2
DEBUG POINT 3
"The Owner is....." (if Owner is within range)
DEBUG POINT 4 (if Owner is within range)
DEBUG POINT 5
DEBUG POINT 6
DEBUG POINT 7
"GlobalTarget has been [CORRECTLY/INCORRECTLY] populated" (dependant on whether GlobalTarget == GetOwner())
DEBUG POINT 8
BUT what is actually being produced is:
DEBUG POINT 1 (correctly populated)
DEBUG POINT 2 (correctly populated)
DEBUG POINT 7 (should be name of Owner but is actually name of Object)
"GlobalTarget has been INCORRECTLY populated"
DEBUG POINT 8 (should be name of Owner but is actually name of Object)
DEBUG POINT 3 (correctly populated)
"The Owner is....."
DEBUG POINT 4 (correctly populated)
DEBUG POINT 5 (correctly populated)
DEBUG POINT 6 (correctly populated)
So, what am I misunderstanding or doing wrong & how do I correct it?
Thanks in advance

DebbieT
XxX