Since I’m not a programmer, I don’t understand a lot of the content in the programming manual. Could you please teach me with simple examples?
First question: How to pass variables into Gui's callback function?
I do not want to redefine the variables cfgFileDir and cfgArrRB inside the saveRbIni function. How to pass the variables cfgFileDir and cfgArrRB into the saveRbIni function?
My configuration file is named "text.ini" and has the following content:
Code: Select all
[RB]
bp = 6
lv75 = 7
lv50 = 5
lv35 = 2
lv20 = 2
lv1 = 2
Code: Select all
SetWorkingDir(A_ScriptDir)
#SingleInstance Force
CoordMode("Pixel", "Window")
SetTitleMatchMode("RegEx")
^!v::
{
cfgRead(fileDir, section, arr) {
for key in arr
RBGui[key].value := IniRead(fileDir, section, key)
}
cfgSave(guiObj, fileDir, section, arr) {
for key in arr {
guiValue := guiObj[key].value
if (guiValue != IniRead(fileDir, section, key)) {
IniWrite(guiValue, fileDir, section, key)
}
}
}
cfgFileDir := "text.ini"
cfgArrRB := ["bp", "lv75", "lv50", "lv35", "lv20", "lv1"]
RBGui := Gui("AlwaysOnTop Resize", "test")
RBGui.Add("GroupBox", "h195 w180", "RB_Cfg")
RBGui.Add("Text", "XM+5 YM+20", "BP")
RBGui.Add("Edit", "w30 h17 XP+110 YP-2")
RBGui.Add("UpDown", "vbp Range0-6 Wrap", 2)
RBGui.Add("Text", "XM+5 YM+45", "Lv.75")
RBGui.Add("Edit", "w30 h17 XP+110 YP-2")
RBGui.Add("UpDown", "vlv75 Range0-7 Wrap", 6)
RBGui.Add("Text", "XM+5 YM+70", "Lv.50")
RBGui.Add("Edit", "w30 h17 XP+110 YP-2")
RBGui.Add("UpDown", "vlv50 Range0-7 Wrap", 5)
RBGui.Add("Text", "XM+5 YM+95", "Lv.35")
RBGui.Add("Edit", "w30 h17 XP+110 YP-2")
RBGui.Add("UpDown", "vlv35 Range0-7 Wrap", 2)
RBGui.Add("Text", "XM+5 YM+120", "Lv.20")
RBGui.Add("Edit", "w30 h17 XP+110 YP-2")
RBGui.Add("UpDown", "vlv20 Range0-7 Wrap", 2)
RBGui.Add("Text", "XM+5 YM+145", "Lv.1")
RBGui.Add("Edit", "w30 h17 XP+110 YP-2")
RBGui.Add("UpDown", "vlv1 Range0-7 Wrap", 2)
RBGui.Add("Button", "default XM+110 YM+165", "OK").OnEvent("Click", rbFunc)
RBGui.Add("Button", "-default XM+10 YM+165", "Save_Cfg").OnEvent("Click", saveRbIni)
cfgRead(cfgFileDir, "RB", cfgArrRB)
RBGui.Show()
saveRbIni(*) {
cfgFileDir := "text.ini"
cfgArrRB := ["bp", "lv75", "lv50", "lv35", "lv20", "lv1"]
cfgSave(RBGui, cfgFileDir, "RB", cfgArrRB)
}
rbFunc(*) {
Saved := RBGui.Submit()
RBGui.Destroy()
; ...
}
}
Second question: How to terminate another function within one function?
Start the autoFunc and errFind functions. The autoFunc function contains multiple color judgment operations within a lot of loops. Regardless of where the autoFunc function is currently running, how can I terminate the autoFunc function and continue to the next iteration when the errFind function detects an error?
Code: Select all
^!c::
{
autoFunc() {
; ...
loop {
Sleep(1000)
if (1 = 1) {
break
}
}
loop {
Sleep(1000)
if (2 = 2) {
break
}
}
; ...
loop {
Sleep(1000)
if (9999 = 9999) {
break
}
}
}
errFind(a, b, c) {
; ...
SetTimer(() => errFind(a, b, c), -10000)
}
a := 1, b := 2, c := 3
errFind(a, b, c)
loop {
autoFunc()
}
}