I'm curently trying to dump my debug/message handling to a seperate script (so i get more space in my mainscripts).
I'm using the link_message event to communicate with this script and send a code to the debug script (as well as some flags). So i'm using the 2nd parameter of link_message, to put most of the informations in it, 3rd parameter is for custom messages and last one reserved for keys (i.e. for whispers).
Most of it seems to work fine, but i have some problems reading out some of the flags and i receive some weird and unexpected results. I've been looking for hours, for the error, but i really can't find any. And it's unlikely an SL error either, cause i ge same results in LSLEditor too.
The code looks something similar to:
//####################################
// Constants
//####################################
integer DEBUGLEVEL = 1;
integer DEBUG_FATAL = 1;
integer DEBUG_CRITICAL = 2;
integer DEBUG_WARNING = 3;
integer DEBUG_INFO = 4;
integer DEBUG_ALWAYS = 5;
integer DEBUG_RESERVED1_FLAG = 0x00004000; // Reserved
integer DEBUG_RESERVED2_FLAG = 0x00008000; // Reserved
integer DEBUG_DEBUGCHANNEL = 0x00080000; // DEBUG_CHANNEL
integer DEBUG_OWNERSAY = 0x00100000; // llOwnerSay
integer DEBUG_SAY = 0x00200000; // llSay
integer DEBUG_WHISPER = 0x00400000; // llWhisper
integer DEBUG_INSTANTMESSSAGE = 0x00800000; // llInstantMessage
integer DEBUG_MESSAGELINKED = 0x01000000; // llMessageLinked
integer DEBUG_HTTPREQUEST = 0x02000000; // slSafeHTTPRequest
//integer DEBUG_UNUSED = 0x04000000; // Unused
// Masks
integer DEBUG_MESSAGEID_MASK = 0x00003fff; // 14 Bit for Messagecodes
integer DEBUG_DEBUGLEVEL_MASK = 0x00070000; // Debug Level
integer DEBUG_MESSAGETYPE_MASK = 0x03f80000; // Message Type Mask
integer DEBUG_CHAN_NUMBER_MASK = 0xFC000000; // Chan number mask
string SERVER_URL = "http://serverurl";
default
{
state_entry() {
}
touch(integer total_number){
// Testdata on Click
integer num = 1533; // Channel
llOwnerSay((string)num);
num = (num & ~DEBUG_CHAN_NUMBER_MASK) | (25<<26);
llOwnerSay((string)num);
num = num | (DEBUG_WARNING<<16); // DEBUG_FATAL
llOwnerSay((string)num);
num = num | (DEBUG_OWNERSAY | DEBUG_WHISPER | DEBUG_DEBUGCHANNEL);
llOwnerSay((string)num);
llMessageLinked(LINK_THIS, num, "", llGetOwner());
}
link_message(integer sender_number, integer number, string message, key id) {
if(number>=1000) {
// Only process our messages
integer msg_num = number & DEBUG_MESSAGEID_MASK;
integer debuglevel = (number & DEBUG_DEBUGLEVEL_MASK) >> 16;
integer chan_num = number >> 26;
integer flags = number & DEBUG_MESSAGETYPE_MASK;
llOwnerSay("Number: "+(string)number+"\nMsg id: "+(string)msg_num+"\nDebug level: "+(string)debuglevel+"\nChannel Number: "+(string)chan_num+"\nFlags:"+flags);
string debug_msg;
if(DEBUGLEVEL!=0) {
if(debuglevel==DEBUG_FATAL) {
debug_msg = "Fatal Error: ";
} else if(debuglevel==DEBUG_CRITICAL) {
debug_msg = "Critical Error: ";
} else if(debuglevel==DEBUG_WARNING) {
debug_msg = "Warning: ";
} else if(debuglevel==DEBUG_INFO) {
debug_msg = "Debuginfo: ";
}
} else if(debuglevel==DEBUG_ALWAYS){
debug_msg = message;
}
integer index = llListFindList(msg_list, [msg_num]);
if(index!=-1){
debug_msg += llList2String(msg_list, index+1);
// Thats where the bug shows, only DEBUG_DEBUGCHANNEL, DEBUG_OWNERSAY will be displayed, whisper not
if((flags & DEBUG_DEBUGCHANNEL)==DEBUG_DEBUGCHANNEL) {
llSay(DEBUG_CHANNEL, "DBG:"+debug_msg);
}
if((flags & DEBUG_OWNERSAY)== DEBUG_OWNERSAY) {
llOwnerSay("Owner:"+debug_msg);
}
if((flags & DEBUG_SAY)==DEBUG_SAY) {
llSay(chan_num, "Say:"+debug_msg);
}
if((flags & DEBUG_WHISPER)==DEBUG_WHISPER) {
llWhisper(chan_num, "Whis:"+debug_msg);
}
if((flags & DEBUG_INSTANTMESSSAGE)==DEBUG_INSTANTMESSSAGE) {
if(id!=NULL_KEY) {
llInstantMessage(id, "IM:"+debug_msg);
}
}
if((flags & DEBUG_MESSAGELINKED)==DEBUG_MESSAGELINKED) {
llOwnerSay("DEBUG_MESSAGELINKED not implemented yet"
;}
if((flags & DEBUG_HTTPREQUEST==DEBUG_HTTPREQUEST)) {
llOwnerSay("DEBUG_HTTPREQUEST not implemented yet"
;}
}
}
}
}
When i click on the script, it executes and i get this as output:
[18:20] Debug-test: 1533
[18:20] Debug-test: 1677723133
[18:20] Debug-test: 1677919741
[18:20] Debug-test: 1683686909
[18:20] Debug-test: Number: 1683686909
Msg id: 1533
Debug level: 3
Channel Number: 25
Flags:5767168
[18:20] Debug-test: Owner:Warning: Test Message
Let it go step by step and look at the "num" as binary
00000000 00000000 00000101 11111101 = 1533 1533
01100100 00000000 00000101 11111101 = 1677723133 1533 | (25<<26)
01100100 00000011 00000101 11111101 = 1677919741 1533 | (25<<26) | (DEBUG_WARNING<<16)
01100100 01011011 00000101 11111101 = 1683686909 1533 | (25<<26) | (DEBUG_WARNING<<16) | (DEBUG_OWNERSAY | DEBUG_WHISPER | DEBUG_DEBUGCHANNEL)
So we got
01011011 but, the flags i set, was
00010000 DEBUG_OWNERSAY
01000000 DEBUG_WHISPER
00001000 DEBUG_DEBUGCHANNEL
So far so good.
But
if((flags & DEBUG_WHISPER)==DEBUG_WHISPER) {
llWhisper(chan_num, "Whis:"+debug_msg);
}
fails and is never entered. Why?! I have absolutly no expaination for this. So my next step was to display the values and their AND'ed result.
So basicly i came to:
01100100 01011011 00000101 11111101 = 1683686909 = 0x645B05FD
&
00000011 11111000 00000000 00000000 = 66584576 = 0x03f80000
--------------------------------------------------------------
00000000 01011000 00000000 00000000 = 5767168 = 0x00580000
How in gods name, can i get such a result?
Everything seems fine, but i dont get a whisper.
When i uncomment
num = (num & ~DEBUG_CHAN_NUMBER_MASK) | (25<<26);
it seems to work. But i can't imagine, how these two going to interfere each other, since the "25" is left-shifted just beyond the flags bits (and the test value also show that they haven't changed any of the flag bits by shifting.