具有AutoHotkey的Roblox Studio中具有Lua代码模板的Roblox代码自动化

开发软件时,自动化是关键。 这包括自动化重复的任务,例如构建管道,还包括编码和键入。 代码模板和自动完成功能是最节省生产力的代码之一。

Roblox Studio带有自动完成功能(有时不起作用),但是它没有代码模板。 但是不要担心,您可以使用文本扩展器创建自己的代码模板。

AutoHotkey是一个非常强大的免费开放源代码Windows自动化工具。 它已经存在了很长一段时间,并且在全球范围内被各种IT专业人员(以及非专业人员)广泛使用。 根据他们的网站:

Windows的终极自动化脚本语言。 AutoHotkey是Windows的一种免费的开放源代码脚本语言,它使用户可以轻松地为各种任务创建小型到复杂的脚本,例如:表格填充,自动单击,宏等。

我自己是一名程序员,自2004年问世以来,我就一直在使用它,我可以说我离不开它。

继续,下载并安装它:https://autohotkey.com/download/。 官方文档:https://autohotkey.com/docs/AutoHotkey.htm。

AutoHotkey具有一项称为 Hotstrings 的功能 ,这是我们将要使用的功能。 使用Hotstrings,您可以定义一个文本缩写,您希望将其替换为另一个单词,短语甚至是多行文本。 您还可以模拟任何击键(例如:{enter} {left 2},以放置ENTER并将插入号向左移动两次)。

打开记事本或任何其他文本编辑器,然后创建一个新文件。

Roblox脚本中最常见的行之一是: local parent = script.Parent或通常声明为local sp = script.Parent 。 如何为该行创建模板?

  :*:xsp :: local sp = script.Parent`n 

哇! 这是什么废话? 坚持,稍等! 它比看起来容易:

  :*: -这告诉AutoHotkey这是一个Hotstring 
xsp-这是我们的缩写
:: -这是缩写和输出之间的分隔符
local sp = script.Parent`n-当我们键入xsp时将被替换。 反引号n( `n )表示换行。

保存文件并将其另存为roblox-templates.ahk 。 双击将其打开,然后在后台执行AutoHotkey。 您可以在系统任务栏中的AutoHotkey图标中看到正在运行的文件。 您可以随时通过右键单击图标来暂停和暂停热键。

同样,只要您修改.ahk文件,就必须单击那里的“重新加载此脚本”。

只需打开Roblox Studio并键入您的任何缩写。 在我们的例子中,让我们测试一下我们刚刚创建的那个。 在Lua脚本中键入xsp 。 这是发生了什么:

当然,您可以将缩写修改为所需的任何名称 ,例如/ sp,localsp,scriptparent等。

假设您有一个放置方法的模板,然后只想在扩展后键入参数。 这意味着将插入号移到括号中。 调用{left [要移动的量]}以模拟LEFT键的按键操作。

  :*:xwfc ::: WaitForChild(“”){左2} 

如果您完全按照我的方式尝试了上述示例,则可能对您不起作用,因为键入了spxwfc而不是xwfc 。 当您使用:*时,AutoHotkey期望单独使用缩写。

要使其在现有字词中起作用(如上述示例),请添加?。 之后:* 。 例:

  :* ?: xwfc ::: WaitForChild(“”){左2} 

使用AutoHotkey和#IfWinActive命令,我们可以隔离缩写和模板以仅在某些程序中运行! 就我们而言,我们可以将模板隔离到Roblox Studio。

首先,运行AutoHotkey Window Spy以获取应用程序名称:右键单击系统任务栏图标-> Window Spy- >使Roblox Studio成为活动程序,然后复制ahk_exe [Something]行 ,如我在此处所示:

现在,在您的.ahk脚本中,将模板放在#IfWinActive返回子句中:

  #IfWinActive,ahk_exe RobloxStudioBeta.exe 
:*:xsp :: local sp = script.Parent`n
:* ?: xwfc ::: WaitForChild(“”){左2}
返回

重新加载AutoHotkey(右键单击系统任务栏->重新加载此脚本),就可以开始了!

原始模板

如果模板中的字符与AutoHotkey的命令和语法冲突,则可以将其放在花括号内,特别是冒号(:)。 例:

  :*:xeq :: tool.Equipped {:} connnect(){left} 

多行模板

您可以使用`n{Enter}或Continuation Sections。

  #IfWinActive,ahk_exe RobloxStudioBeta.exe 
:*:l; :: local {Space}
:*:llf :: local函数{空格}
:*:localsp :: local sp = script.Parent`n
:*:getreplicated :: local ReplicatedStorage = game:GetService(“ ReplicatedStorage”)`n
:*:getscriptservice :: local ServerScriptService = game:GetService(“ ServerScriptService”)`n
:*:getsstorage :: local ServerStorage = game:GetService(“ ServerStorage”)`n
:*:getphysics :: local PhysicsService =游戏:GetService(“ PhysicsService”)`n
:*:localtool :: local工具= script.Parent`n
:* ?: waitchild ::: WaitForChild(“”){left 2}
:* ?: firstchild :::: FindFirstChild(“”){left 2}
:*:tooleq :: tool.Equipped {:} connnect(){left}
:*:tooluneq :: tool.Unequipped {:} connnect(){left}
:*:getservice :: game:GetService(“”){左2}
:* ?: econnect :: {:} connect {(} {)} {left}
:* ?: connectfn :: {:} connect {(} function {(} {)} {Enter} {up} {End} {Left}
:*:mtuple :: local tuple = {{} ... {}}`n
:*:inew :: Instance.new(“”){左2}
:*:v3new :: Vector3.new(){左}
:*:cfnew :: CFrame.new(){左}
:*:cfang :: CFrame.Angles(){left}
:*:c3new :: Color3.new(){左}
:*:gwork :: game.Workspace
:* ?: brickcolor :: .. BrickColor = BrickColor.new(“”){left}
:*:mrand :: math.random(){左}
:*:/ delay :: delay(,function {(} {)} {Enter} {up} ^ {left} ^ {right} ^ {right} {left 2}
:*?:/ cf :: CFrame。
:*?:/ v3 :: Vector3。
:*?:/ p ::父母
:* ?: gethumanoid :: local humanoid = player.Character {:} WaitForChild(“ Humanoid”)`n
:* ?: gettorso :: local torso = player.Character {:} WaitForChild(“ Torso”)`n
:*:infwhile :: while true做{Enter}
:* ?: kids :: {:} GetChildren()`n
:*:tins :: table.insert(){左}
:*:trem :: table.remove(){左}
返回

如果您担心AutoHotkey是安全的软件,请检查以下链接。 社区为自己说话。

AutoHotkey基金会

该文档可在此处以PDF格式下载。 AutoHotkey Foundation LLC的名称直接来自……的名称。

autohotkey.com

AutoHotkey –维基百科

AutoHotkey是一种免费的开放源代码的自定义脚本语言,适用于Microsoft Windows,最初旨在提供简单易用的…

en.wikipedia.org

它的官方论坛有数千名成员和帖子:

https://autohotkey.com/boards/

Google搜索返回380万个结果,主要是教程,文档等:

https://www.google.com.br/search?q=autohotkey&oq=autoh&ie=UTF-8