2013-09-29 3 views
1

내 자신의 GUI를 스크립팅하는 방법을 배우는 중입니다. Koda는 큰 도움이되어 왔습니다. 한 번에 작은 비트를 배우면서 그걸로 장난하고 있습니다. 그러나 나는 주변에서 벗어날 수없는 오류가 발생했습니다. 현재 작업중인 GUI는 게임의 봇 설정을 변경하는 간단한 도구입니다. 이 gui에는 난이도 설정을위한 5 개의 버튼과 봇 수에 대한 체크 박스 목록이 있어야합니다.Autoit GUI, 버튼 누름에서 변수가 선언되지 않음

하지만, 나는이 오류 얻을 저장 나는 난이도, 봇 번호, 공격을 선택할 때 : 오류이 줄로 발생되는

'Variable used without being declared' 

(끝 botSAVE 버튼) :

FileWriteLine($file2, "aiSettings.setMaxNBots " & $botnum)  

버튼 기능 'Func numClick()'이 눌린 버튼을 기반으로이 변수를 설정한다고 생각했지만 분명히 뭔가를 간과했습니다. 다행히도 그것은 쉬운 문제입니다. 아무도이 오류의 원인이 무엇인지 보지 못합니까? 나는이 질문을 autoitcsript 포럼에 올렸지 만 게임 자동화 스크립트에서 벗어나려는 것 같아서저기서 많은 도움을 얻지 못했습니다. 사람 -if

#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 

내가 잘못 한 일을보고, 또는 버튼 클릭으로 선언 변수를 커버하는 주제에 대한 링크를 가지고, 도움말 항상 감사합니다. 내가 찾은 유일한 주제는 매우 모호하거나, 내가 본 것과 약간 다를 수 있습니다.

답변

2

함수 외부에서 변수 값을 사용하려는 경우 범위를 전역으로 선언해야합니다. 따라서 많은 함수 선언 앞에 Global $botnum (아마도 기본값을가집니다)을 추가하십시오 ...

분명히 $skillset과 동일합니다.

Opt("MustDeclareVars", 1)을 사용했기 때문에 오류가 발생했습니다. 하지만이 변수를 전역 변수로 선언하지 않으면 함수에서 값이 설정되지만 함수가 끝나면 다시 무시되므로이 변수는 아무 것도 작동하지 않습니다. 따라서 다른 함수에서 초기화되지 않은 변수를 사용할 때는 항상 초기화되지 않은 변수의 기본값을 받게됩니다.

+0

Global로 설정하면 해결되었습니다. – MHFSU

관련 문제