You declared the constant twice. This code, however, will fail to work.
function onServerStart()
{
const MyConstant = "Hi";
print(MyConstant);
MyConstant = "Glad to see you :) ";
print(MyConstant);
}
Scripts/Main/Main.nut line = (6) column = (14) : error can't assign expression
I see no reason to use them as global variables anyways, since you'd have to use const every time you want to redeclare it, and they cannot be redefined like this, which a lot of scripts will require:
function onServerStart()
{
MyConstant = "MyData";
}
Besides, constants are supposed to be... well, constant. This is absolutely bad practice. Want to use constants as global variables? Then use global variables.
function onServerStart()
{
// Create a global variable
MyGlobalVariable <- "MyData";
print(MyGlobalVariable);
// Change it
MyGlobalVariable = "MyOtherData";
print(MyGlobalVariable); // <-- this works
}
</rant>