Code: Select all
global current_step := 1 ; It's values are added in other functions, as well as in step[]. It isn't relevant for this
global step:=[]
Next_Step(){
if (current_step = 1) {
for a, b in myArray["main",step[1]] {
MsgBox % a "-" b
}
}
else if (current_step = 2) {
for a, b in myArray["main",step[1],"secundary",step[2]] {
MsgBox % a "-" b
}
}
else if (current_step = 3) {
for a, b in myArray["main",step[1],"secundary",step[2],"tertiary",step[3]] {
MsgBox % a "-" b
}
}
}
Code: Select all
Next_Step(){
for a, b in myArray[templateArray[current_step] {
MsgBox % a "-" b
}
}
I am thinking on filling the templateArray from the beggining with a structure like this
Code: Select all
templateArray := [ " "main",step[1]" ", " "main",step[1],"secundary",step[2]" ", " "main",step[1],"secundary",step[2],"tertiary",step[3] " ]
A fast way to test if I am close to get where I am trying to be, would be this
Code: Select all
step_value_1:="myValue"
template_one = "main", %step_value_1% ; Alternative one
template_one := """main""" "," """" step_value_1 """" ; Alternative two
for a,b in json[template_one] {
MsgBox % a "-" b
}
Thanks!
Edit: Clarify
Problem: How to pass a variable to myArray that contains a sub commands for a specific myArray value
So instead of doing this
Code: Select all
for a, b in myArray["main",step[1]] {
MsgBox % a "-" b
}
Code: Select all
template_one = "main", %step[1]%
for a,b in json[template_one] {
MsgBox % a "-" b
}
EDIT 2: Clarify
I want to access a value in an nested associative array as in the following structure
Code: Select all
secundary := { keyA: "ValueA"
, keyA: "ValueA"}
myArray := { secundary: secundary }
Code: Select all
MsgBox % myArray["secundary", "keyA"] ; This display ValueA in a MsgBox
But I need to have stored the commands
Code: Select all
"secundary","keyA"
Code: Select all
myArray["secundary","keyA"] ; Access ValueA
Code: Select all
myArray[tmp] ; Access ValueA
CONCLUSION:
I asked in Reddit as well here Broken Link for safety
And in the end I got 2 solutions
1. From G33kDude Broken Link for safety
Code: Select all
secondary:= { keyA: "ValueA", keyB: "ValueA"}
myArray := { secondary: secondary }
MsgBox, % myArray["secondary", "keyA"] ; This display ValueA
tmp := ["secondary","keyA"]
MsgBox, % myArray[tmp*] ; This display ValueA
Code: Select all
InnerArray := {keyA: "ValueA", keyB: "ValueB"}
OuterArray := {InnerArray: InnerArray}
Tmp := "InnerArray,keyA"
MsgBox, % OuterArray[StrSplit(Tmp, ",")*]