我仍在学习如何编写自己的 GUI 脚本。Koda 帮了我很大的忙,我一直在玩弄它,一次学习一点点。但是,我遇到了一个似乎无法解决的错误。我正在使用的当前 GUI 是一个用于更改游戏机器人设置的简单工具。这个 gui 应该有 5 个用于难度设置的按钮,以及一个用于机器人数量的复选框列表。
但是,当我选择难度级别、机器人编号并点击保存时,我收到此错误:
'Variable used without being declared'
此行发生错误(最后的 botSAVE 按钮):
FileWriteLine($file2, "aiSettings.setMaxNBots " & $botnum)
我认为按钮功能“Func numClick()”根据按下的按钮设置了这个变量,但显然我忽略了一些东西。希望这是一个简单的修复。有人看到可能导致此错误的原因吗?我已经在 autoitcsript 论坛上发布了这个问题,但他们似乎回避了游戏自动化脚本,所以我在那里并没有真正得到太多帮助。
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)
#Region ### START Koda GUI section ### Form=c:\users\admin\desktop\form1.kxf
$Form1 = GUICreate("Battlefield 2 Bot-Tool", 418, 499, 759, 83)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "Form1Minimize")
GUISetOnEvent($GUI_EVENT_MAXIMIZE, "Form1Maximize")
GUISetOnEvent($GUI_EVENT_RESTORE, "Form1Restore")
$Pic1 = GUICtrlCreatePic("C:\Users\admin\Desktop\bflogo.jpg", 0, 0, 417, 233)
$Settings = GUICtrlCreateTab(8, 240, 401, 249)
GUICtrlSetOnEvent(-1, "SettingsChange")
$Bot = GUICtrlCreateTabItem("Bots")
$botSAVE = GUICtrlCreateButton("Save these changes", 220, 433, 169, 33)
GUICtrlSetOnEvent(-1, "botSAVEClick")
$botDEFAULT = GUICtrlCreateButton("Restore default settings", 28, 433, 169, 33)
GUICtrlSetOnEvent(-1, "botDEFAULTClick")
$botskill = GUICtrlCreateGroup(" Bot skill level", 28, 265, 169, 145)
$skill1 = GUICtrlCreateRadio(" RECRUIT", 44, 289, 113, 17)
GUICtrlSetTip(-1, "Easy opposition, a damn turkey shoot")
GUICtrlSetOnEvent(-1, "skill1Click")
$skill2 = GUICtrlCreateRadio(" TRAINED", 44, 313, 113, 17)
GUICtrlSetTip(-1, "Default setting, opponents are deadly at close range")
GUICtrlSetOnEvent(-1, "skill2Click")
$skill3 = GUICtrlCreateRadio(" HARDENED", 44, 337, 113, 17)
GUICtrlSetTip(-1, "Enemies are a force to be reckoned with")
GUICtrlSetOnEvent(-1, "skill3Click")
$skill4 = GUICtrlCreateRadio(" VETERAN", 44, 361, 113, 17)
GUICtrlSetTip(-1, "Enemies are experienced, and dangerous")
GUICtrlSetOnEvent(-1, "skill4Click")
$skill5 = GUICtrlCreateRadio(" ELITE", 44, 385, 113, 17)
GUICtrlSetTip(-1, "Crack shot opponents will strategize against you. You will not survive")
GUICtrlSetOnEvent(-1, "skill5Click")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$botnumber = GUICtrlCreateGroup(" Number of bots ", 220, 265, 169, 145)
$num1 = GUICtrlCreateRadio("2", 236, 289, 25, 17)
GUICtrlSetOnEvent(-1, "num1Click")
$num2 = GUICtrlCreateRadio("4", 236, 313, 25, 17)
GUICtrlSetOnEvent(-1, "num2Click")
$num3 = GUICtrlCreateRadio("6", 236, 337, 25, 17)
GUICtrlSetOnEvent(-1, "num3Click")
$num4 = GUICtrlCreateRadio("8", 236, 361, 25, 17)
GUICtrlSetOnEvent(-1, "num4Click")
$num5 = GUICtrlCreateRadio("10", 236, 385, 33, 17)
GUICtrlSetOnEvent(-1, "num5Click")
$num6 = GUICtrlCreateRadio("12", 284, 289, 33, 17)
GUICtrlSetOnEvent(-1, "num6Click")
$num7 = GUICtrlCreateRadio("14", 284, 313, 33, 17)
GUICtrlSetOnEvent(-1, "num7Click")
$num8 = GUICtrlCreateRadio("16", 284, 337, 33, 17)
GUICtrlSetOnEvent(-1, "num8Click")
$num9 = GUICtrlCreateRadio("18", 284, 361, 33, 17)
GUICtrlSetOnEvent(-1, "num9Click")
$num10 = GUICtrlCreateRadio("20", 284, 385, 33, 17)
GUICtrlSetOnEvent(-1, "num10Click")
$num11 = GUICtrlCreateRadio("24", 340, 289, 33, 17)
GUICtrlSetOnEvent(-1, "num11Click")
$num12 = GUICtrlCreateRadio("28", 340, 313, 33, 17)
GUICtrlSetOnEvent(-1, "num12Click")
$num13 = GUICtrlCreateRadio("32", 340, 337, 33, 17)
GUICtrlSetOnEvent(-1, "num13Click")
$num14 = GUICtrlCreateRadio("36", 340, 361, 33, 17)
GUICtrlSetOnEvent(-1, "num14Click")
$num15 = GUICtrlCreateRadio("40", 340, 385, 33, 17)
GUICtrlSetOnEvent(-1, "num15Click")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Server = GUICtrlCreateTabItem("Server")
$serverDEFAULT = GUICtrlCreateButton("Restore default settings", 28, 433, 169, 33)
$serverSAVE = GUICtrlCreateButton("Save these changes", 220, 433, 169, 33)
GUICtrlCreateTabItem("")
GUISetState(@SW_SHOW)
Opt("MustDeclareVars",1)
#EndRegion ### END Koda GUI section ###
While 1
Sleep(100)
WEnd
Func Form1Close()
If @GUI_WINHANDLE = $Form1 Then
Exit
EndIf
EndFunc
Func Form1Maximize()
EndFunc
Func Form1Minimize()
EndFunc
Func Form1Restore()
EndFunc
Func num1Click()
$botnum = "2"
EndFunc
Func num2Click()
$botnum = "4"
EndFunc
Func num3Click()
$botnum = "6"
EndFunc
Func num4Click()
$botnum = "8"
EndFunc
Func num5Click()
$botnum = "10"
EndFunc
Func num6Click()
$botnum = "12"
EndFunc
Func num7Click()
$botnum = "14"
EndFunc
Func num8Click()
$botnum = "16"
EndFunc
Func num9Click()
$botnum = "18"
EndFunc
Func num10Click()
$botnum = "20"
EndFunc
Func num11Click()
$botnum = "24"
EndFunc
Func num12Click()
$botnum = "28"
EndFunc
Func num13Click()
$botnum = "32"
EndFunc
Func num14Click()
$botnum = "36"
EndFunc
Func num15Click()
$botnum = "40"
EndFunc
Func SettingsChange()
EndFunc
Func skill1Click()
$skillset = "0.1"
EndFunc
Func skill2Click()
$skillset = "0.3"
EndFunc
Func skill3Click()
$skillset = "0.6"
EndFunc
Func skill4Click()
$skillset = "0.8"
EndFunc
Func skill5Click()
$skillset = "1.0"
EndFunc
Func botDEFAULTClick()
EndFunc
Func botSAVEClick()
Local $file = FileOpen("AIDefault.ai", 1)
If $file = -1 Then
MsgBox(0, "Protected file", "Please ensure that the file 'AIDefault.ai' is not set to Read Only.")
exit
EndIf
FileWriteLine($file, "aiSettings.setNSides 2 ")
FileWriteLine($file, "aiSettings.setAutoSpawnBots 1 ")
FileWriteLine($file, "aiSettings.setMaxNBots 64 ")
FileWriteLine($file, "aiSettings.maxBotsIncludeHumans 1")
FileWriteLine($file, "aiSettings.setBotSkill 0.4 ")
FileWriteLine($file, "run BotNames.ai ")
FileWriteLine($file, "aiSettings.setInformationGridDimension 32")
FileWriteLine($file, "run AIPathFinding.ai")
FileWriteLine($file, "run AIBotChanger.ai ")
FileClose($file)
$file2 = FileOpen("AIBotChanger.ai", 1)
If $file2 = -1 Then
MsgBox(0, "Protected file", "Please ensure that the file 'AIBotChanger.ai' is not set to Read Only.")
Exit
EndIf
FileWriteLine($file2, "aiSettings.overrideMenuSettings 1")
FileWriteLine($file2, "aiSettings.setMaxNBots " & $botnum)
FileWriteLine($file2, "aiSettings.setBotSkill " & $skillset)
FileWriteLine($file2, "aiSettings.maxBotsIncludeHumans 0")
FileClose($file2)
EndFunc
- 如果有人看到我做错了什么,或者有一个链接到一个主题的链接,该主题涵盖了通过单击按钮声明变量,总是感谢帮助。我发现的唯一主题非常模糊,或者与我正在寻找的内容略有不同