08-06-2003 10:46
I realize we have LL-provided common constants, but to the best of my knowledge, we can't declare our own. (Please, somebody correct me if I'm wrong.)

I realize that we can declare and name variables to make them seem like constants, but there's a critical difference.

This code results in a logic error, that could be a pain to debug in a large script:

CODE

integer CHAN_PUBLIC = 0;

default
{
state_entry()
{
}

listen(integer channel, string name, key id, string message)
{
if (CHAN_PUBLIC = channel)
{
// Code always executes, UNLESS channel is 0
}
}
}


This code, on the other hand, would result in a compiler error, and the bug would never occur in the first place:

CODE

const integer CHAN_PUBLIC = 0;

default
{
state_entry()
{
}

listen(integer channel, string name, key id, string message)
{
if (CHAN_PUBLIC = channel) // Compiler error, can't assign to constant
{
}
}
}
_____________________
Grim

"God only made a few perfect heads, the rest of them he put hair on." -- Unknown