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
{
}
}
}