Scripting: Do's and Don'ts – Arma Reforger
Jump to navigation
Jump to search
Don't | Do |
---|---|
Don't | Do |
---|---|
Don't | Do |
---|---|
switch (value)
{
case 0:
{
Print("0");
break;
}
default:
{
Print("default");
break;
}
} |
switch (value)
{
case 0:
Print("0");
break;
default: // brackets are needed only if variables are declared in the 'case' code
{ // otherwise scoping is superfluous (and very slightly impacts performance)
string message = "default";
Print(message);
break;
}
} |
Don't | Do |
---|---|
// this array only lists pointers but does not increase the reference count
array<ExampleClass> classArray = {};
ExampleClass newInstance;
for (int i; i < 10; i++)
{
newInstance = new ExampleClass();
classArray.Insert(newInstance);
// newInstance will be deleted at the end of the scope
// as there are no references to it
} |
Don't | Do |
---|---|
class MainClass
{
ref SubClass m_SubClass;
void MainClass()
{
m_SubClass = new SubClass(this);
}
}
class SubClass
{
ref MainClass m_Parent;
void SubClass(MainClass parent)
{
m_Parent = parent;
}
void DoSomething()
{
Print(m_Parent);
}
} |
class MainClass
{
ref SubClass m_SubClass;
void MainClass()
{
m_SubClass = new SubClass(this);
}
}
class SubClass
{
MainClass m_Parent; // ref removed
void SubClass(MainClass parent)
{
m_Parent = parent;
}
void DoSomething()
{
if (!m_Parent) // null safety check
return;
Print(m_Parent);
}
} |