Then what is wrong with my script?
I am trying to make two elevators. This is the script from what I call the "Elevator control panel". It is supposed to receive commands from the caller-buttons, calculate the difference they have from both elevators and then, if the left one has a bigger difference from the right one, send the right one to the caller's floor or else send the left one to the caller's floor.
This is my script so far...
integer RLevel; // Right elevator's level
integer LLevel; // Left elevator's level
integer CLevel; // Caller's level
string sRLevel; // Right elevator's level (string)
string sLLevel; // Left elevator's level (string)
string sCLevel; // Caller's level (string)
integer RDiff; // Right elevator's difference from caller's level
integer LDiff; // Left elevator's difference from caller's level
default
{
state_entry()
{
ShowText = 1;
llSetText("Starting up", <1,1,0>, 1);
llRegionSay(-1, "R90"); // This tells the right elevator to go to ground level
RLevel = 0;
llRegionSay(-1, "L90"); // This tells the left elevator to go to ground level
LLevel = 0;
llRegionSay(-1, "0D190"); // This opens the right ground level's door
llRegionSay(-1, "0D290"); // This opens the left ground level's door
llRegionSay(-1, "1D191"); //*
llRegionSay(-1, "1D291"); //*
llRegionSay(-1, "2D191"); //*
llRegionSay(-1, "2D291"); //*
//* = Closes a door
llListen(-1, "", "", "");
llSetText("Waiting for command", <0,1,0>, 1);
}
listen(integer channel, string name, key id, string message)
{
llSetText("Got command", <0,1,0>, 1);
if (message == "901") // This is from caller button the digit in the middle (0 in this case) indicates the level
{
CLevel = 0;
}
else if (message == "911")
{
CLevel = 1;
}
else if (message == "921")
{
CLevel = 2;
}
llSetText("Finding nearest elevator", <0,1,0>, ShowText);
if (LLevel < CLevel)
{
LDiff = CLevel - LLevel;
}
else if (LLevel > CLevel)
{
LDiff = LLevel - CLevel;
}
if (RLevel < CLevel)
{
RDiff = CLevel - RLevel;
}
else if (RLevel > CLevel)
{
RDiff = RLevel - CLevel;
}
llSetText("Changing variables to strings", <0,1,0>, 1);
sRLevel = (string)RLevel;
sLLevel = (string)LLevel;
sCLevel = (string)CLevel;
llSetText("Calling elevator", <0,1,0>, 1);
if (RDiff < LDiff)
{
llRegionSay(-1, sRLevel + "D191"); // Right elevator's door close
llRegionSay(-1, sCLevel + "911"); // Tell the caller that the right elevator is comming
llRegionSay(-1, "R9" + sCLevel); // Right elevator go to caller level
RLevel = CLevel;
llRegionSay(-1, sCLevel + "D190"); // Door open
}
else
{
llRegionSay(-1, sLLevel + "D291"); // Left elevator's door close
llRegionSay(-1, sCLevel + "912"); // Tell the caller that the left elevator is coming
llRegionSay(-1, "L9" + sCLevel); // Left elevator go to caller level
LLevel = CLevel;
llRegionSay(-1, sCLevel + "D290"); // Door open
}
llSetText("Waiting for command", <0,1,0>, 1);
}
}