Scripting Temporary Feature – Arma Reforger
Jump to navigation
Jump to search
Lou Montana (talk | contribs) m (Add frequently used flags) |
Lou Montana (talk | contribs) m (Text replacement - "Workbench" to "{{GameCategory|armaR|Modding|Official Tools|text= Workbench}}") |
||
(3 intermediate revisions by the same user not shown) | |||
Line 27: | Line 27: | ||
} | } | ||
} | } | ||
} | } | ||
</enforce> | </enforce> | ||
Line 65: | Line 65: | ||
#endif | #endif | ||
} | } | ||
} | } | ||
</enforce> | </enforce> | ||
Line 71: | Line 71: | ||
{{Feature|informative|Useful frequently used flags: | {{Feature|informative|Useful frequently used flags: | ||
* {{hl|WORKBENCH}} - if the | * {{hl|WORKBENCH}} - if the {{GameCategory|armaR|Modding|Official Tools|text= Workbench}} executable is running | ||
* {{hl|PLATFORM_CONSOLE}} - if the platform is a game console (Xbox, etc) | * {{hl|PLATFORM_CONSOLE}} - if the platform is a game console (Xbox, etc) | ||
}} | }} | ||
Line 78: | Line 78: | ||
A preprocessor value can be defined in two ways: | A preprocessor value can be defined in two ways: | ||
* preprocessor definition, using <enforce inline>#define TAG_ACTIVATE_FEATURE</enforce> - required in every file that uses it. Can be commented with {{hl|//}} | * preprocessor definition, using <enforce inline>#define TAG_ACTIVATE_FEATURE</enforce> at the top of the file - required in every file that uses it. Can be commented with {{hl|//}} | ||
* the [[Arma Reforger:Startup Parameters#scrDefine|scrDefine]] startup parameter {{hl| | * the [[Arma Reforger:Startup Parameters#scrDefine|scrDefine]] startup parameter {{hl|ArmaReforgerSteam.exe -scrDefine TAG_ACTIVATE_FEATURE}} | ||
{{GameCategory|armaR|Modding|Tutorials|Scripting}} | {{GameCategory|armaR|Modding|Tutorials|Scripting}} |
Latest revision as of 20:08, 5 April 2024
Developing or updating a feature may happen over the course of multiple days and sometimes having the ability to switch it on/off for feature or performance comparison is a good thing. Multiple options are available.
Bool Switch
class TAG_TestEntity : GenericEntity
{
[Attribute(defvalue: "0")]
protected bool m_bActivateFeature; // can be changed during runtime with SetActivateFeature
void SetActivateFeature(bool activate)
{
m_bActivateFeature = activate;
}
void PublicMethod()
{
if (m_bActivateFeature)
{
// feature actions
}
else
{
// old/no feature actions
}
}
}
Preprocessor If
Sometimes a bool switch is not a possible solution (due to required data initialisation or other systems, etc). A preprocessor definition can be used:
class TAG_TestEntity : GenericEntity
{
protected ref array<int> m_aObjectData;
#ifdef TAG_ACTIVATE_FEATURE
protected ref array<int> m_aNewFeatureData; // this will not exist at all in the object if the flag is not defined, therefore no reference/memory will be attributed
#endif
void PublicMethod()
{
#ifdef TAG_ACTIVATE_FEATURE
// feature actions
#else
// old/no feature actions - m_aNewFeatureData can NOT be referenced as it does not exist here
#endif
}
void TAG_TestEntity()
{
m_aObjectData = {};
#ifdef TAG_ACTIVATE_FEATURE
// all these operations will not happen at all - actually, all these instructions will not even exist if the flag is not defined
m_aNewFeatureData = {};
for (int i = 0; i < 1001; i++)
{
m_aNewFeatureData.Insert(i * 2);
}
#endif
}
}
This is very often used with #ifdef WORKBENCH across Arma Reforger code, allowing code to only be compiled for Workbench usage (saving memory space in game).
Definition
A preprocessor value can be defined in two ways:
- preprocessor definition, using #define TAG_ACTIVATE_FEATURE at the top of the file - required in every file that uses it. Can be commented with
/ / - the scrDefine startup parameter ArmaReforgerSteam.exe -scrDefine TAG_ACTIVATE_FEATURE