Script Editor Plugin – Arma Reforger
Jump to navigation
Jump to search
Lou Montana (talk | contribs) (Page creation) |
Lou Montana (talk | contribs) m (Text replacement - "{{Link|OFPEC tags" to "{{Link|Scripting Tags") |
||
(6 intermediate revisions by 2 users not shown) | |||
Line 2: | Line 2: | ||
This tutorial teaches how to create a {{Link|Arma Reforger:Script Editor}}-specific plugin. | This tutorial teaches how to create a {{Link|Arma Reforger:Script Editor}}-specific plugin. | ||
{{Feature|important|Please read {{Link|Arma Reforger:Workbench Plugin}} | {{Feature|important|Please read {{Link|Arma Reforger:Workbench Plugin}} before following this tutorial.}} | ||
Line 8: | Line 8: | ||
* Open Script Editor | * Open Script Editor | ||
* In an addon, create a new script in {{hl|WorkbenchGame/ScriptEditor}} - name it {{hl| | * In an addon, create a new script in {{hl|WorkbenchGame/ScriptEditor}} - name it {{hl|{{Link|Scripting Tags|TAG_}}TutorialPlugin.c}} (must end with {{hl|Plugin}} by convention) | ||
* Double-click the file to open it | * Double-click the file to open it | ||
* Press {{Controls|Ctrl|T}} to use the Script Template plugin | * Press {{Controls|Ctrl|T}} to use the {{Link|Arma Reforger:Script Editor: Fill From Template Plugin|Script Template plugin}} | ||
** In its window, select "Class Type: WorkbenchPlugin", leave the other fields blank/default | ** In its window, select "Class Type: WorkbenchPlugin", leave the other fields blank/default | ||
** A Workbench plugin skeleton is inserted. | ** A Workbench plugin skeleton is inserted. | ||
* In the {{hl|WorkbenchPluginAttribute}}, replace <enforce inline>wbModules: { "ResourceManager" }</enforce> by <enforce inline>wbModules: { "ScriptEditor" }</enforce> | * In the {{hl|WorkbenchPluginAttribute}}, replace <enforce inline>wbModules: { "ResourceManager" }</enforce> by <enforce inline>wbModules: { "ScriptEditor" }</enforce> | ||
* In the <enforce inline>Run()</enforce> method, write <enforce inline>Print("It works!");</enforce> and save the file | * In the <enforce inline>Run()</enforce> method, write <enforce inline>Print("It works!");</enforce> and save the file | ||
* | * Reload Workbench scripts via '''Reload WB Scripts''' option located in ''Plugins→Settings'' menu (default shortcut: {{Controls|Ctrl|Shift|R}}) | ||
* The {{hl|TAG_TutorialPlugin}} plugin should appear in the Script Editor's Plugins list, available in the top bar - click on the plugin entry | * The {{hl|TAG_TutorialPlugin}} plugin should appear in the Script Editor's Plugins list, available in the top bar - click on the plugin entry | ||
* "It works!" gets printed in the output console. | * "It works!" gets printed in the output console. | ||
Line 22: | Line 22: | ||
== ScriptEditor Module API == | == ScriptEditor Module API == | ||
In the below code, the {{hl|GetCurrentLine}} method is used to get the cursor location's line number. | {{Feature|informative|See the {{Link/Enfusion|armaR|ScriptEditor}} class.}} | ||
The {{hl|GetLineText}}/{{hl|SetLineText}} methods | |||
In the below code, the {{hl|GetCurrentLine}} method is used to get the cursor location's line number (0-based index, first line = 0, second line = 1, etc). | |||
The {{hl|GetLineText}}/{{hl|SetLineText}} methods are used to obtain and change the line's value by adding an inline comment indicating the current line number ("hardcoded" into the comment). | |||
<enforce> | <enforce> | ||
Line 29: | Line 31: | ||
class TAG_TutorialPlugin : WorkbenchPlugin | class TAG_TutorialPlugin : WorkbenchPlugin | ||
{ | { | ||
//------------------------------------------------------------------------------------------------ | |||
override void Run() | override void Run() | ||
{ | { | ||
Line 40: | Line 43: | ||
} | } | ||
</enforce> | </enforce> | ||
{{Feature|important|Each text operation goes into one {{Controls|Ctrl|Z}} '''each''', making reverting a multi-line text operation successive Ctrl+Zs.}} | {{Feature|important|Each text operation goes into one {{Controls|Ctrl|Z}} '''each''', making reverting a multi-line text operation successive Ctrl+Zs.}} | ||
== | |||
== Configuration == | |||
Displayed parameters are declared values decorated with an {{hl|Attribute}}; a full setup is done as follow: | Displayed parameters are declared values decorated with an {{hl|Attribute}}; a full setup is done as follow: | ||
Line 54: | Line 59: | ||
protected bool m_bOnlyLineNumber; | protected bool m_bOnlyLineNumber; | ||
//------------------------------------------------------------------------------------------------ | |||
override void Run() | override void Run() | ||
{ | { | ||
Line 63: | Line 69: | ||
if (lineContent.IsEmpty()) | if (lineContent.IsEmpty()) | ||
{ | { | ||
Workbench.Dialog("Empty line", "You cannot add a comment to a completely empty line."); | Workbench.Dialog("Empty line", "You cannot add a comment to a completely empty line."); // absolutely arbitrary tutorial decision :) | ||
return; | return; | ||
} | } | ||
Line 75: | Line 81: | ||
} | } | ||
//------------------------------------------------------------------------------------------------ | |||
override void Configure() | override void Configure() | ||
{ | { | ||
Line 81: | Line 88: | ||
} | } | ||
</enforce> | </enforce> | ||
{{GameCategory|armaR|Modding|Tutorials|Scripting|Workbench}} | {{GameCategory|armaR|Modding|Tutorials|Scripting|Workbench}} |
Latest revision as of 12:03, 2 October 2024
This tutorial teaches how to create a Script Editor-specific plugin.
Setup
- Open Script Editor
- In an addon, create a new script in WorkbenchGame
/ScriptEditor - name it TAG_TutorialPlugin.c (must end with Plugin by convention) - Double-click the file to open it
- Press Ctrl + T to use the Script Template plugin
- In its window, select "Class Type: WorkbenchPlugin", leave the other fields blank/default
- A Workbench plugin skeleton is inserted.
- In the WorkbenchPluginAttribute, replace wbModules: { "ResourceManager" } by wbModules: { "ScriptEditor" }
- In the Run() method, write Print("It works!"); and save the file
- Reload Workbench scripts via Reload WB Scripts option located in Plugins→Settings menu (default shortcut: Ctrl + ⇧ Shift + R)
- The TAG_TutorialPlugin plugin should appear in the Script Editor's Plugins list, available in the top bar - click on the plugin entry
- "It works!" gets printed in the output console.
ScriptEditor Module API
In the below code, the GetCurrentLine method is used to get the cursor location's line number (0-based index, first line = 0, second line = 1, etc). The GetLineText/SetLineText methods are used to obtain and change the line's value by adding an inline comment indicating the current line number ("hardcoded" into the comment).
[WorkbenchPluginAttribute(name: "Tutorial Plugin", description: "This tutorial plugin does something.", shortcut: "Ctrl+Shift+H", wbModules: { "ScriptEditor" }, awesomeFontCode: 0xF188)]
class TAG_TutorialPlugin : WorkbenchPlugin
{
//------------------------------------------------------------------------------------------------
override void Run()
{
ScriptEditor scriptEditor = Workbench.GetModule(ScriptEditor);
int lineNumber = scriptEditor.GetCurrentLine();
string lineContent;
scriptEditor.GetLineText(lineContent);
lineContent += " // current line is " + (lineNumber + 1);
scriptEditor.SetLineText(lineContent);
}
}
Configuration
Displayed parameters are declared values decorated with an Attribute; a full setup is done as follow:
[WorkbenchPluginAttribute(name: "Tutorial Plugin", description: "This tutorial plugin does something.", shortcut: "Ctrl+Shift+H", wbModules: { "ScriptEditor" }, awesomeFontCode: 0xF188)]
class TAG_TutorialPlugin : WorkbenchPlugin
{
[Attribute(desc: "Only display the line number without any other text")]
protected bool m_bOnlyLineNumber;
//------------------------------------------------------------------------------------------------
override void Run()
{
ScriptEditor scriptEditor = Workbench.GetModule(ScriptEditor);
int lineNumber = scriptEditor.GetCurrentLine();
string lineContent;
scriptEditor.GetLineText(lineContent);
if (lineContent.IsEmpty())
{
Workbench.Dialog("Empty line", "You cannot add a comment to a completely empty line."); // absolutely arbitrary tutorial decision :)
return;
}
if (m_bOnlyLineNumber)
lineContent += " // " + (lineNumber + 1).ToString();
else
lineContent += " // current line is " + (lineNumber + 1).ToString();
scriptEditor.SetLineText(lineContent);
}
//------------------------------------------------------------------------------------------------
override void Configure()
{
Workbench.ScriptDialog("Tutorial Plugin Configuration", "Usage:\nTick the checkbox or not, depending on if the line number should be written or not", this);
}
}